Skip to content
This repository has been archived by the owner on Mar 3, 2022. It is now read-only.

Commit

Permalink
Remove interactive setup.
Browse files Browse the repository at this point in the history
  • Loading branch information
stephencelis committed Jan 9, 2012
1 parent 928c26b commit ced028d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 43 deletions.
26 changes: 12 additions & 14 deletions lib/ghi.rb
Expand Up @@ -10,13 +10,10 @@ def login
return @login if defined? @login return @login if defined? @login
@login = `git config --get github.user`.chomp @login = `git config --get github.user`.chomp
if @login.empty? if @login.empty?
begin warn "Please configure your GitHub username."
print "Please enter your GitHub username: " puts
@login = gets.chomp puts "E.g., git config --global github.user [your username]"
valid = user? @login abort
warn "invalid username" unless valid
end until valid
`git config --global github.user #@login`
end end
@login @login
end end
Expand All @@ -25,13 +22,14 @@ def token
return @token if defined? @token return @token if defined? @token
@token = `git config --get github.token`.chomp @token = `git config --get github.token`.chomp
if @token.empty? if @token.empty?
begin warn "Please configure your GitHub token."
print "GitHub token (https://github.com/account): " puts
@token = gets.chomp puts "E.g., git config --global github.user [your token]"
valid = token? @token puts
warn "invalid token for #{login}" unless valid puts "Find your token here: https://github.com/account/admin"
end until valid abort
`git config --global github.token #@token` elsif @token.sub!(/^!/, '')
@token = `#@token`
end end
@token @token
end end
Expand Down
29 changes: 0 additions & 29 deletions spec/ghi_spec.rb
Expand Up @@ -59,33 +59,4 @@
GHI.should_receive(:`).once.and_return "da39a3ee5e6b4b0d3255bfef95601890\n" GHI.should_receive(:`).once.and_return "da39a3ee5e6b4b0d3255bfef95601890\n"
GHI.token.should == "da39a3ee5e6b4b0d3255bfef95601890" GHI.token.should == "da39a3ee5e6b4b0d3255bfef95601890"
end end

it "should approve login input" do
GHI.instance_eval { instance_variable_defined?(:@login).should == false }
GHI.should_receive(:`).with("git config --get github.user").
and_return "\n"
GHI.should_receive(:print).twice
GHI.should_receive(:gets).twice.and_return "defunct\n", "defunkt\n"
Net::HTTP.should_receive(:get).and_return "500: invalid: response",
LOGGED_OUT_YAML
GHI.should_receive(:warn).once
GHI.should_receive(:`).with("git config --global github.user defunkt").
and_return "\n"
GHI.login.should == "defunkt"
end

it "should approve token input" do
GHI.instance_eval { instance_variable_defined?(:@token).should == false }
GHI.stub!(:login).and_return "defunkt"
GHI.should_receive(:`).with("git config --get github.token").
and_return "\n"
GHI.should_receive(:print).twice
token = "da39a3ee5e6b4b0d3255bfef95601890"
GHI.should_receive(:gets).and_return "invalid\n", "#{token}\n"
Net::HTTP.should_receive(:get).and_return LOGGED_OUT_YAML, LOGGED_IN_YAML
GHI.should_receive(:warn).once
GHI.should_receive(:`).with("git config --global github.token #{token}").
and_return "\n"
GHI.token.should == token
end
end end

0 comments on commit ced028d

Please sign in to comment.