Class: AboutYml::AboutFile
- Inherits:
-
Object
- Object
- AboutYml::AboutFile
- Defined in:
- lib/about_yml/about.rb
Class Method Summary collapse
- .add_github_metadata(result, repo) ⇒ Object
- .fetch_file_contents(client, repo_full_name) ⇒ Object
- .fetch_from_github(github_org, access_key) ⇒ Object
- .organize_by_owner_type_and_name(abouts) ⇒ Object
- .schema ⇒ Object
- .validate_about_files(repo_name_to_about_data) ⇒ Object
- .validate_single_file(about_data) ⇒ Object
- .write_error(err, repo, result) ⇒ Object
Class Method Details
.add_github_metadata(result, repo) ⇒ Object
45 46 47 48 49 50 |
# File 'lib/about_yml/about.rb', line 45 def self.(result, repo) result['github'] = { 'name' => repo.full_name, 'description' => repo.description, } end |
.fetch_file_contents(client, repo_full_name) ⇒ Object
34 35 36 37 |
# File 'lib/about_yml/about.rb', line 34 def self.fetch_file_contents(client, repo_full_name) about = client.contents repo_full_name, path: '.about.yml' SafeYAML.load Base64.decode64(about['content']) end |
.fetch_from_github(github_org, access_key) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/about_yml/about.rb', line 21 def self.fetch_from_github(github_org, access_key) client = Octokit::Client.new access_token: access_key repos = client.org_repos github_org result = { 'public' => {}, 'private' => {}, 'missing' => [], 'errors' => {}, } repos.each { |repo| collect_repository_data repo, client, result } result end |
.organize_by_owner_type_and_name(abouts) ⇒ Object
81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/about_yml/about.rb', line 81 def self.organize_by_owner_type_and_name(abouts) abouts.values.each_with_object({}) do |about, result| owner_type = about['owner_type'] name = about['name'] if owner_type && name (result[owner_type] ||= {})[name] = about else alt_id = about['full_name'] ? about['full_name'] : about['name'] result[alt_id + '/' + about['type']] = about end end end |
.schema ⇒ Object
12 13 14 15 16 17 18 19 |
# File 'lib/about_yml/about.rb', line 12 def self.schema @schema ||= begin raw_schema = File.read File.join(File.dirname(__FILE__), 'schema.json') schema = ::JSON.parse raw_schema ::JSON::Validator.fully_validate_schema schema schema end end |
.validate_about_files(repo_name_to_about_data) ⇒ Object
68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/about_yml/about.rb', line 68 def self.validate_about_files(repo_name_to_about_data) r = { 'valid' => {}, 'invalid' => {} } repo_name_to_about_data.each_with_object(r) do |data, results| repo, contents = data errors = validate_single_file contents if errors.empty? results['valid'][repo] = contents else results['invalid'][repo] = { errors: errors, contents: contents } end end end |
.validate_single_file(about_data) ⇒ Object
64 65 66 |
# File 'lib/about_yml/about.rb', line 64 def self.validate_single_file(about_data) ::JSON::Validator.fully_validate schema, about_data end |
.write_error(err, repo, result) ⇒ Object
39 40 41 42 43 |
# File 'lib/about_yml/about.rb', line 39 def self.write_error(err, repo, result) $stderr.puts('Error while parsing .about.yml for ' \ "#{repo.full_name}:\n #{err}") result['errors'][repo.full_name] = err. end |