From c3fe6784591c0b4446ec5041bdc8db096ae70b95 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kirill=20M=C3=BCller?= Date: Tue, 29 Oct 2013 00:56:00 +0100 Subject: [PATCH] `ci-status -v` prints the URL to CI build results Fixes #422, closes #423 --- features/ci_status.feature | 14 ++++++++++++++ features/steps.rb | 5 ++++- lib/hub/commands.rb | 15 +++++++++++++-- man/hub.1 | 9 ++++++--- man/hub.1.html | 10 ++++++---- man/hub.1.ronn | 6 ++++-- 6 files changed, 47 insertions(+), 12 deletions(-) diff --git a/features/ci_status.feature b/features/ci_status.feature index f036c06b..85f35e4c 100644 --- a/features/ci_status.feature +++ b/features/ci_status.feature @@ -11,6 +11,13 @@ Feature: hub ci-status Then the output should contain exactly "success\n" And the exit status should be 0 + Scenario: Fetch commit SHA with URL + Given there is a commit named "the_sha" + Given the remote commit state of "michiels/pencilbox" "the_sha" is "success" + When I run `hub ci-status the_sha -v` + Then the output should contain "success: https://travis-ci.org/michiels/pencilbox/builds/1234567" + And the exit status should be 0 + Scenario: Multiple statuses, latest is passing Given there is a commit named "the_sha" Given the remote commit states of "michiels/pencilbox" "the_sha" are: @@ -41,6 +48,13 @@ Feature: hub ci-status Then the output should contain exactly "no status\n" And the exit status should be 3 + Scenario: Exit status 3 for no statuses available without URL + Given there is a commit named "the_sha" + Given the remote commit state of "michiels/pencilbox" "the_sha" is nil + When I run `hub ci-status -v the_sha` + Then the output should contain exactly "no status\n" + And the exit status should be 3 + Scenario: Abort with message when invalid ref given When I run `hub ci-status this-is-an-invalid-ref` Then the exit status should be 1 diff --git a/features/steps.rb b/features/steps.rb index be6c5dda..a2bcb8ad 100644 --- a/features/steps.rb +++ b/features/steps.rb @@ -175,7 +175,10 @@ Given(/^the remote commit states of "(.*?)" "(.*?)" are:$/) do |proj, ref, json_ end Given(/^the remote commit state of "(.*?)" "(.*?)" is "(.*?)"$/) do |proj, ref, status| - step %{the remote commit states of "#{proj}" "#{ref}" are:}, "[ { :state => \"#{status}\" } ]" + step %{the remote commit states of "#{proj}" "#{ref}" are:}, <<-EOS + [ { :state => \"#{status}\", + :target_url => 'https://travis-ci.org/#{proj}/builds/1234567' } ] + EOS end Given(/^the remote commit state of "(.*?)" "(.*?)" is nil$/) do |proj, ref| diff --git a/lib/hub/commands.rb b/lib/hub/commands.rb index 9dcd361f..dbf7817d 100644 --- a/lib/hub/commands.rb +++ b/lib/hub/commands.rb @@ -78,6 +78,7 @@ module Hub def ci_status(args) args.shift ref = args.words.first || 'HEAD' + verbose = args.include?('-v') unless head_project = local_repo.current_project abort "Aborted: the origin remote doesn't point to a GitHub repository." @@ -89,7 +90,13 @@ module Hub statuses = api_client.statuses(head_project, sha) status = statuses.first - ref_state = status ? status['state'] : 'no status' + if status + ref_state = status['state'] + ref_target_url = status['target_url'] + else + ref_state = 'no status' + ref_target_url = nil + end exit_code = case ref_state when 'success' then 0 @@ -98,7 +105,11 @@ module Hub else 3 end - $stdout.puts ref_state + if verbose and ref_target_url + $stdout.puts "%s: %s" % [ref_state, ref_target_url] + else + $stdout.puts ref_state + end exit exit_code end diff --git a/man/hub.1 b/man/hub.1 index e99bd2e5..ebcb71a2 100644 --- a/man/hub.1 +++ b/man/hub.1 @@ -1,7 +1,7 @@ .\" generated with Ronn/v0.7.3 .\" http://github.com/rtomayko/ronn/tree/0.7.3 . -.TH "HUB" "1" "July 2013" "GITHUB" "Git Manual" +.TH "HUB" "1" "October 2013" "GITHUB" "Git Manual" . .SH "NAME" \fBhub\fR \- git + hub = github @@ -64,7 +64,7 @@ \fBgit pull\-request\fR [\fB\-f\fR] [\fB\-m\fR \fIMESSAGE\fR|\fB\-F\fR \fIFILE\fR|\fB\-i\fR \fIISSUE\fR|\fIISSUE\-URL\fR] [\fB\-b\fR \fIBASE\fR] [\fB\-h\fR \fIHEAD\fR] . .br -\fBgit ci\-status\fR [\fICOMMIT\fR] +\fBgit ci\-status\fR [\fB\-v\fR] [\fICOMMIT\fR] . .SH "DESCRIPTION" hub enhances various git commands to ease most common workflows with GitHub\. @@ -155,12 +155,15 @@ Without \fIMESSAGE\fR or \fIFILE\fR, a text editor will open in which title and If instead of normal \fITITLE\fR an issue number is given with \fB\-i\fR, the pull request will be attached to an existing GitHub issue\. Alternatively, instead of title you can paste a full URL to an issue on GitHub\. . .TP -\fBgit ci\-status\fR [\fICOMMIT\fR] +\fBgit ci\-status\fR [\fB\-v\fR] [\fICOMMIT\fR] Looks up the SHA for \fICOMMIT\fR in GitHub Status API and displays the latest status\. Exits with one of: . .br success (0), error (1), failure (1), pending (2), no status (3) . +.IP +If \fB\-v\fR is given, additionally print the URL to CI build results\. +. .SH "CONFIGURATION" Hub will prompt for GitHub username & password the first time it needs to access the API and exchange it for an OAuth token, which it saves in "~/\.config/hub"\. . diff --git a/man/hub.1.html b/man/hub.1.html index 8482fc9c..039226d3 100644 --- a/man/hub.1.html +++ b/man/hub.1.html @@ -101,7 +101,7 @@ git compare [-u] [USER] [START...]END
git fork [--no-remote]
git pull-request [-f] [-m MESSAGE|-F FILE|-i ISSUE|ISSUE-URL] [-b BASE] [-h HEAD]
-git ci-status [COMMIT]

+git ci-status [-v] [COMMIT]

DESCRIPTION

@@ -194,9 +194,11 @@ Pull request message can also be passed via stdin with -F -.

If instead of normal TITLE an issue number is given with -i, the pull request will be attached to an existing GitHub issue. Alternatively, instead of title you can paste a full URL to an issue on GitHub.

-
git ci-status [COMMIT]

Looks up the SHA for COMMIT in GitHub Status API and displays the latest +

git ci-status [-v] [COMMIT]

Looks up the SHA for COMMIT in GitHub Status API and displays the latest status. Exits with one of:
-success (0), error (1), failure (1), pending (2), no status (3)

+success (0), error (1), failure (1), pending (2), no status (3)

+ +

If -v is given, additionally print the URL to CI build results.

@@ -453,7 +455,7 @@ $ git help hub
  1. GITHUB
  2. -
  3. July 2013
  4. +
  5. October 2013
  6. hub(1)
diff --git a/man/hub.1.ronn b/man/hub.1.ronn index 2c048cb4..76cca8f9 100644 --- a/man/hub.1.ronn +++ b/man/hub.1.ronn @@ -28,7 +28,7 @@ hub(1) -- git + hub = github `git compare` [`-u`] [] [...] `git fork` [`--no-remote`] `git pull-request` [`-f`] [`-m` |`-F` |`-i` |] [`-b` ] [`-h` ] -`git ci-status` [] +`git ci-status` [`-v`] [] ## DESCRIPTION @@ -154,11 +154,13 @@ hub also adds some custom commands that are otherwise not present in git: request will be attached to an existing GitHub issue. Alternatively, instead of title you can paste a full URL to an issue on GitHub. - * `git ci-status` []: + * `git ci-status` [`-v`] []: Looks up the SHA for in GitHub Status API and displays the latest status. Exits with one of: success (0), error (1), failure (1), pending (2), no status (3) + If `-v` is given, additionally print the URL to CI build results. + ## CONFIGURATION Hub will prompt for GitHub username & password the first time it needs to access