Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

display server errors when creating pullrequest fails

Closes #114
  • Loading branch information...
commit 4072568cdc251537fcb61306cda4efec444289f4 1 parent 027c3d1
@mislav mislav authored
Showing with 18 additions and 1 deletion.
  1. +7 −1 lib/hub/commands.rb
  2. +11 −0 test/hub_test.rb
View
8 lib/hub/commands.rb
@@ -970,7 +970,13 @@ def self.===(exception)
def display_http_exception(action, response)
$stderr.puts "Error #{action}: #{response.message} (HTTP #{response.code})"
- warn "Check your token configuration (`git config github.token`)" if response.code.to_i == 401
+ case response.code.to_i
+ when 401 then warn "Check your token configuration (`git config github.token`)"
+ when 422
+ if response.content_type =~ /\bjson\b/ and data = JSON.parse(response.body) and data["error"]
+ $stderr.puts data["error"]
+ end
+ end
end
end
View
11 test/hub_test.rb
@@ -882,6 +882,17 @@ def test_pullrequest_existing_issue_url
assert_output expected, "pull-request https://github.com/mojombo/hub/issues/92#comment_4"
end
+ def test_pullrequest_fails
+ stub_request(:post, "https://#{auth}github.com/api/v2/json/pulls/defunkt/hub").
+ to_return(:status => [422, "Unprocessable Entity"],
+ :headers => {"Content-type" => "application/json"},
+ :body => %({"error":["oh no!", "it failed."]}))
+
+ expected = "Error creating pull request: Unprocessable Entity (HTTP 422)\n"
+ expected << "oh no!\nit failed.\n"
+ assert_output expected, "pull-request hereyougo -b feature -f"
+ end
+
def test_checkout_no_changes
assert_forwarded "checkout master"
end
Please sign in to comment.
Something went wrong with that request. Please try again.