Permalink
Browse files

If GitHub credentials aren't available then it asks for them.

  • Loading branch information...
1 parent a90d332 commit 12602e480c65e9bd9e601563c4fb77829baba294 @drnic drnic committed Jan 30, 2011
Showing with 24 additions and 23 deletions.
  1. +0 −4 Gemfile.lock
  2. +15 −8 lib/github/command.rb
  3. +9 −11 spec/command_spec.rb
View
@@ -31,9 +31,5 @@ PLATFORMS
DEPENDENCIES
activerecord (~> 2.3.10)
github!
- highline (~> 1.5.1)
- json (~> 1.4.6)
- launchy (~> 0.3.7)
rake
rspec (~> 1.3.1)
- text-format (= 1.0.0)
View
@@ -68,21 +68,28 @@ def die(message)
def github_user
user = git("config --get github.user")
- if user.empty?
- die("You must 'git config --global github.user [your Github username]' before running this command")
- end
-
+ request_github_credentials && github_user if user.empty?
user
end
def github_token
token = git("config --get github.token")
- if token.empty?
- die("You must 'git config --global github.token [your API token]' before running this command")
- end
-
+ request_github_credentials && github_token if token.empty?
token
end
+
+ def request_github_credentials
+ puts "Please enter your GitHub credentials:"
+ user = highline.ask("Username: ")
+ git("config --global github.user '#{user}'")
+ token = highline.ask("Token: ")
+ git("config --global github.token '#{token}'")
+ true
+ end
+
+ def highline
+ @highline ||= HighLine.new
+ end
def shell_user
ENV['USER']
View
@@ -79,18 +79,16 @@
@command.should_receive(:exit!).once
@command.die "message"
end
-
- it "should die if a github API token cannot be found" do
- @command.should_receive(:git).once.with("config --get github.token").and_return("")
- @command.should_receive(:puts).once.with("=> You must 'git config --global github.token [your API token]' before running this command")
- @command.should_receive(:exit!).once
- @command.github_token
- end
-
- it "should die if a github username token cannot be found" do
+
+ it "requests github API credentials if not found" do
@command.should_receive(:git).once.with("config --get github.user").and_return("")
- @command.should_receive(:puts).once.with("=> You must 'git config --global github.user [your Github username]' before running this command")
- @command.should_receive(:exit!).once
+ @command.should_receive(:puts).once.with("Please enter your GitHub credentials:")
+ h = mock("HighLine")
+ h.should_receive(:ask).once.with("Username: ").and_return("drnic")
+ h.should_receive(:ask).once.with("Token: ").and_return("TOKEN")
+ @command.should_receive(:highline).twice.and_return(h)
+ @command.should_receive(:git).once.with("config --global github.user 'drnic'")
+ @command.should_receive(:git).once.with("config --global github.token 'TOKEN'")
@command.github_user
end
end

0 comments on commit 12602e4

Please sign in to comment.