class CodeInventory::CLI::App

Public Instance Methods

github(org) click to toggle source
# File lib/codeinventory_plugin.rb, line 15
def github(org)
  unless !options["access-token"].nil? ^ !options["client-credentials"].nil? ^ !options["login"].nil?
    puts "One authentication method is required (-a, -c, or -l)"
    exit 1
  end
  auth = {}
  if !options["access-token"].nil?
    auth = { access_token: options["access-token"] }
  elsif !options["client-credentials"].nil?
    values = options["client-credentials"].split(":")
    unless values.count == 2
      puts "You must provide client credentials in the format CLIENT_ID:CLIENT_SECRET"
      exit 1
    end
    auth = { client_id: values[0], client_secret: values[1] }
  elsif !options["login"].nil?
    values = options["login"].split(":")
    unless values.count == 2
      puts "You must provide a login in the format USERNAME:PASSWORD"
      exit 1
    end
    auth = { login: values[0], password: values[1] }
  end
  source = CodeInventory::GitHub::Source.new(auth, org, overrides: options[:overrides], exclude: options[:exclude])
  inventory = CodeInventory::Inventory.new(source)
  agency = options["agency-name"] || org
  output = inventory.generate(agency, "2.0.0")
  puts JSON.pretty_generate(output)
end