Class: CodeInventory::Source::GitHub
- Inherits:
-
Object
- Object
- CodeInventory::Source::GitHub
- Defined in:
- lib/codeinventory/source/github.rb
Instance Attribute Summary collapse
-
#org ⇒ Object
Returns the value of attribute org.
Instance Method Summary collapse
- #client ⇒ Object
-
#initialize(access_token:, org:) ⇒ GitHub
constructor
A new instance of GitHub.
- #projects ⇒ Object
Constructor Details
#initialize(access_token:, org:) ⇒ GitHub
Returns a new instance of GitHub.
10 11 12 13 14 |
# File 'lib/codeinventory/source/github.rb', line 10 def initialize(access_token:, org:) Octokit.auto_paginate = true @access_token = access_token @org = org end |
Instance Attribute Details
#org ⇒ Object
Returns the value of attribute org.
8 9 10 |
# File 'lib/codeinventory/source/github.rb', line 8 def org @org end |
Instance Method Details
#client ⇒ Object
42 43 44 |
# File 'lib/codeinventory/source/github.rb', line 42 def client @client ||= Octokit::Client.new(access_token: @access_token) end |
#projects ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/codeinventory/source/github.rb', line 16 def projects repos = client.organization_repositories(@org) projects = [] repos.each do |repo| begin = client.contents(repo[:full_name], path: ".codeinventory.yml") type = :yaml raw_content = Base64.decode64([:content]) rescue Octokit::NotFound begin = client.contents(repo[:full_name], path: ".codeinventory.json") type = :json raw_content = Base64.decode64([:content]) rescue Octokit::NotFound # Ignore repositories that don't have a CodeInventory metadata file end end if type == :yaml projects << YAML.load(raw_content).to_hash elsif type == :json projects << JSON.parse(raw_content) end end projects end |