Skip to content

Commit

Permalink
display server errors when creating pullrequest fails
Browse files Browse the repository at this point in the history
Closes mislav#114
  • Loading branch information
mislav committed Dec 21, 2011
1 parent 027c3d1 commit 4072568
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
8 changes: 7 additions & 1 deletion lib/hub/commands.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 11 additions & 0 deletions test/hub_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 4072568

Please sign in to comment.