Module: Travis::CLI::Gh::GitHub::Authenticated

Included in:
AutoAuth, Login, Signature, Whoami, Write
Defined in:
lib/travis/cli/gh/github.rb

Instance Method Summary collapse

Instance Method Details

#authObject



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/travis/cli/gh/github.rb', line 32

def auth
  load_gh
  @auth ||= Travis::Tools::Github.new(session.config['github']) do |g|
    g.note          = "token for travis-cli-gh"
    g.scopes        = ['user', 'user:email', 'repo']
    g.  = false
    g.explode       = explode?
    g.auto_token    = true
    g.auto_password = true
    g.drop_token    = false
    g.github_token  = plugin_config['token'] || endpoint_config['pr_token']
    g.check_token   = !g.github_token
    g.     = proc { ask("Username: ") }
    g.ask_password  = proc { |user| ask("Password for #{user}: ") { |q| q.echo = "*" } }
    g.ask_otp       = proc { |user| ask("Two-factor authentication code for #{user}: ") }
    g.debug         = proc { |log| debug(log) }
    g.after_tokens  = proc { g.explode = true and error("no suitable github token found, try running gh-login.") }
  end
end

#ghObject



25
26
27
28
29
30
# File 'lib/travis/cli/gh/github.rb', line 25

def gh
  @gh ||= auth.with_token do |token|
    plugin_config['token'] = token
    GH.with(token: token)
  end
end

#plugin_configObject



52
53
54
55
# File 'lib/travis/cli/gh/github.rb', line 52

def plugin_config
  config['gihub'] ||= {}
  config['gihub'][github_endpoint.host] ||= {}
end