diff --git a/.github/category_list.rb b/.github/osia_category_list.rb similarity index 55% rename from .github/category_list.rb rename to .github/osia_category_list.rb index 1364299c..65ac6b6f 100644 --- a/.github/category_list.rb +++ b/.github/osia_category_list.rb @@ -1,8 +1,6 @@ -require 'json' - -c = File.read 'contents.json' -j = JSON.parse c +require_relative 'osia_helper' +j = get_json c = j['categories'] c.sort_by { |h| h['title']} diff --git a/.github/convert.rb b/.github/osia_convert.rb similarity index 98% rename from .github/convert.rb rename to .github/osia_convert.rb index 40ed3a55..04563a78 100644 --- a/.github/convert.rb +++ b/.github/osia_convert.rb @@ -1,45 +1,11 @@ +require_relative 'osia_helper' require 'date' -require 'json' README = 'README.md' ARCHIVE = 'ARCHIVE.md' ARCHIVE_TAG = 'archive' -def output_stars(number) - case number - when 100...200 - '🔥' - when 200...500 - '🔥🔥' - when 500...1000 - '🔥🔥🔥' - when 1000...2000 - '🔥🔥🔥🔥' - when 2000...100000 - '🔥🔥🔥🔥🔥' - else - '' - end -end - -def output_flag(lang) - case lang - when 'jpn' - '🇯🇵' - when 'ltz' - '🇱🇺' - when 'por' - '🇧🇷' - when 'spa' - '🇪🇸' - when 'zho' - '🇨🇳' - else - '' - end -end - def apps_archived(apps) a = apps.select {|a| a['tags'] != nil }.select {|b| b['tags'].include?ARCHIVE_TAG} a.sort_by { |k, v| k['title'] } @@ -103,6 +69,40 @@ def output_apps(apps) o end +def output_flag(lang) + case lang + when 'jpn' + '🇯🇵' + when 'ltz' + '🇱🇺' + when 'por' + '🇧🇷' + when 'spa' + '🇪🇸' + when 'zho' + '🇨🇳' + else + '' + end +end + +def output_stars(number) + case number + when 100...200 + '🔥' + when 200...500 + '🔥🔥' + when 500...1000 + '🔥🔥🔥' + when 1000...2000 + '🔥🔥🔥🔥' + when 2000...100000 + '🔥🔥🔥🔥🔥' + else + '' + end +end + def write_readme(j) t = j['title'] desc = j['description'] @@ -178,8 +178,7 @@ def write_archive(j) puts "wrote #{file} ✨" end -c = File.read 'contents.json' -j = JSON.parse c +j = get_json write_readme(j) write_archive(j) diff --git a/.github/osia_helper.rb b/.github/osia_helper.rb new file mode 100644 index 00000000..f9e0933d --- /dev/null +++ b/.github/osia_helper.rb @@ -0,0 +1,7 @@ +require 'json' + +FILE = 'contents.json' + +def get_json + JSON.parse(File.read FILE) +end diff --git a/.github/update_stars.rb b/.github/osia_update_stars.rb similarity index 89% rename from .github/update_stars.rb rename to .github/osia_update_stars.rb index f227ddd7..c9f7081e 100644 --- a/.github/update_stars.rb +++ b/.github/osia_update_stars.rb @@ -1,15 +1,11 @@ -require 'json' +require_relative 'osia_helper' require 'octokit' require 'netrc' -FILE = 'contents.json' - -c = File.read FILE -j = JSON.parse c - client = Octokit::Client.new(:netrc => true) +j = get_json apps = j['projects'] updated = [] diff --git a/.github/osia_validate_categories.rb b/.github/osia_validate_categories.rb new file mode 100644 index 00000000..6c023ab4 --- /dev/null +++ b/.github/osia_validate_categories.rb @@ -0,0 +1,34 @@ +require_relative 'osia_helper' + +j = get_json +c = j['categories'] +a = j['projects'] + +def failed(cat, app) + puts "‼️ #{cat} is not a valid category for #{app}" + exit 1 +end + +def verify(cat, allowed, app) + failed(cat, app) unless allowed.include? cat +end + +allowed_categories = c.sort_by { |h| h['title']}.map { |x| x['id']} + +a.each do |a| + cat = a['category'] + + if cat.nil? + # failed(cat, a) + puts "missing category for #{a}" + exit 1 + end + + if cat.class == String + verify(cat, allowed_categories, a) + elsif cat.class == Array + cat.each { |c| verify(c, allowed_categories, a) } + end +end + +puts 'categories validated ✅' diff --git a/circle.yml b/circle.yml index e3dbc925..92f2c97d 100644 --- a/circle.yml +++ b/circle.yml @@ -8,6 +8,7 @@ test: override: - awesome_bot contents.json --white-list developer.apple - json validate --schema-file=.github/schema.json --document-file=contents.json + - ruby .github/osia_validate_categories.rb general: artifacts: - "ab-results.json" @@ -15,5 +16,5 @@ deployment: master: branch: master commands: - - ruby .github/convert.rb + - ruby .github/osia_convert.rb - ./.github/deploy.sh