Class: Boxen::Preflight::Creds
Instance Attribute Summary
Attributes inherited from Check
#config
Instance Method Summary
collapse
Methods inherited from Check
#abort, checks, #initialize, register, run, #warn
Constructor Details
This class inherits a constructor from Boxen::Check
Instance Method Details
#basic? ⇒ Boolean
11
12
13
|
# File 'lib/boxen/preflight/creds.rb', line 11
def basic?
config.api.user rescue nil
end
|
#ok? ⇒ Boolean
15
16
17
|
# File 'lib/boxen/preflight/creds.rb', line 15
def ok?
basic? && token?
end
|
#run ⇒ Object
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
|
# File 'lib/boxen/preflight/creds.rb', line 28
def run
console = HighLine.new
warn "Hey, I need your current GitHub credentials to continue."
config.login = console.ask "GitHub login: " do |q|
q.default = config.login || config.user
end
config.password = console.ask "GitHub password: " do |q|
q.echo = "*"
end
unless basic?
puts
abort "Sorry, I can't auth you on GitHub.",
"Please check your credentials and teams and give it another try."
end
unless auth = config.api.authorizations.detect { |a| a.note == "Boxen" }
auth = config.api.create_authorization \
:note => "Boxen", :scopes => %w(repo user)
end
config.token = auth.token
end
|
#token? ⇒ Boolean
19
20
21
22
23
24
25
26
|
# File 'lib/boxen/preflight/creds.rb', line 19
def token?
return unless config.token
tapi = Octokit::Client.new \
:login => config.login, :oauth_token => config.token
tapi.user rescue nil
end
|