Module: Gitomator::GitHub

Defined in:
lib/gitomator/github.rb,
lib/gitomator/github/model/team.rb,
lib/gitomator/github/model/user.rb,
lib/gitomator/github/base_provider.rb,
lib/gitomator/github/hosting_provider.rb,
lib/gitomator/github/tagging_provider.rb,
lib/gitomator/github/model/hosted_repo.rb,
lib/gitomator/github/model/pull_request.rb

Defined Under Namespace

Modules: Model Classes: BaseProvider, HostingProvider, TaggingProvider

Class Method Summary collapse

Class Method Details

.github_client_from_config(config = {}) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/gitomator/github.rb', line 7

def self.github_client_from_config(config = {})
  # Convert keys yo strings (to handle keys whose type is Symbol)
  config = config.map {|k,v| [k.to_s, v]} .to_h

  opts = {}

  if config['access_token']
    opts[:access_token]   = config['access_token']
  elsif config['username'] && config['password']
    opts[:login]          = config['username']
    opts[:password]       = config['password']
  elsif config['client_id'] && config['client_secret']
    opts[:client_id]      = config['client_id']
    opts[:client_secret]  = config['client_secret']
  else
    raise "Invalid GitHub hosting configuration - #{config}"
  end

  require 'octokit'
  return Octokit::Client.new(opts)
end