From 4908b2a77aa434923a2f04f7a8e15bb0fbe25651 Mon Sep 17 00:00:00 2001 From: Travis CI Date: Mon, 16 May 2016 10:22:27 -0700 Subject: [PATCH] [script] validate --- .github/validate_categories.rb | 34 ++++++++++++++++++++++++++++++++++ circle.yml | 1 + 2 files changed, 35 insertions(+) create mode 100644 .github/validate_categories.rb diff --git a/.github/validate_categories.rb b/.github/validate_categories.rb new file mode 100644 index 00000000..3f4a2f49 --- /dev/null +++ b/.github/validate_categories.rb @@ -0,0 +1,34 @@ +require 'json' + +j = JSON.parse(File.read 'contents.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..85b295d5 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/validate_categories.rb general: artifacts: - "ab-results.json"