From f2d3e30bf4c4b375e5bffb224f9f0c2dce5b9deb Mon Sep 17 00:00:00 2001 From: dkhamsing Date: Thu, 19 May 2016 02:13:25 +0000 Subject: [PATCH] [script] improve --- .github/osia_category_list.rb | 3 +-- .github/osia_helper.rb | 4 ++++ .github/osia_validate_categories.rb | 9 ++++----- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/.github/osia_category_list.rb b/.github/osia_category_list.rb index 65ac6b6f..de23f164 100644 --- a/.github/osia_category_list.rb +++ b/.github/osia_category_list.rb @@ -3,5 +3,4 @@ require_relative 'osia_helper' j = get_json c = j['categories'] -c.sort_by { |h| h['title']} - .each { |x| puts x['id']} +osia_allowed_categories(c).each { |cat| puts cat } \ No newline at end of file diff --git a/.github/osia_helper.rb b/.github/osia_helper.rb index f9e0933d..5b691b90 100644 --- a/.github/osia_helper.rb +++ b/.github/osia_helper.rb @@ -5,3 +5,7 @@ FILE = 'contents.json' def get_json JSON.parse(File.read FILE) end + +def osia_allowed_categories(c) + c.sort_by { |h| h['title']}.map { |x| x['id']} +end \ No newline at end of file diff --git a/.github/osia_validate_categories.rb b/.github/osia_validate_categories.rb index 6c023ab4..48303c2d 100644 --- a/.github/osia_validate_categories.rb +++ b/.github/osia_validate_categories.rb @@ -2,7 +2,7 @@ require_relative 'osia_helper' j = get_json c = j['categories'] -a = j['projects'] +apps = j['projects'] def failed(cat, app) puts "‼️ #{cat} is not a valid category for #{app}" @@ -13,13 +13,12 @@ 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']} +allowed_categories = osia_allowed_categories(c) -a.each do |a| +apps.each do |a| cat = a['category'] if cat.nil? - # failed(cat, a) puts "missing category for #{a}" exit 1 end @@ -27,7 +26,7 @@ a.each do |a| if cat.class == String verify(cat, allowed_categories, a) elsif cat.class == Array - cat.each { |c| verify(c, allowed_categories, a) } + cat.each { |d| verify(d, allowed_categories, a) } end end