class AboutYml::AboutFile
Public Class Methods
add_github_metadata(result, repo)
click to toggle source
# File lib/about_yml/about.rb, line 45 def self.add_github_metadata(result, repo) result['github'] = { 'name' => repo.full_name, 'description' => repo.description, } end
fetch_file_contents(client, repo_full_name)
click to toggle source
# 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)
click to toggle source
# 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)
click to toggle source
# 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()
click to toggle source
# 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)
click to toggle source
# 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)
click to toggle source
# 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)
click to toggle source
# 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.message end
Private Class Methods
collect_repository_data(repo, client, result)
click to toggle source
# File lib/about_yml/about.rb, line 52 def self.collect_repository_data(repo, client, result) collection = (repo.private == true) ? 'private' : 'public' repo_name = repo.full_name result[collection][repo_name] = fetch_file_contents client, repo_name add_github_metadata result[collection][repo_name], repo rescue Octokit::NotFound result['missing'] << repo.full_name rescue StandardError => err write_error err, repo, result end