class Chandler::GitHub::Client

A thin wrapper around Octokit::Client that adds support for automatic GitHub Enterprise, .netrc, and ENV token-based authentication.

Public Class Methods

new(host: "github.com", environment: ENV, octokit_client: Octokit::Client) click to toggle source
Calls superclass method
# File lib/chandler/github/client.rb, line 12
def initialize(host: "github.com",
               environment: ENV,
               octokit_client: Octokit::Client)
  options = {}
  options.merge!(detect_auth_option(environment))
  options.merge!(detect_enterprise_endpoint(host))
  super(octokit_client.new(options))
end

Public Instance Methods

login!() click to toggle source
# File lib/chandler/github/client.rb, line 21
def login!
  return if login
  raise netrc ? NetrcAuthenticationFailure : TokenAuthenticationFailure
end

Private Instance Methods

detect_auth_option(env) click to toggle source
# File lib/chandler/github/client.rb, line 28
def detect_auth_option(env)
  if (token = env["CHANDLER_GITHUB_API_TOKEN"])
    { :access_token => token }
  else
    { :netrc => true }
  end
end
detect_enterprise_endpoint(host) click to toggle source
# File lib/chandler/github/client.rb, line 36
def detect_enterprise_endpoint(host)
  return {} if host.downcase == "github.com"
  { :api_endpoint => "https://#{host}/api/v3/" }
end