Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

display server errors when creating pullrequest fails

Closes #114
  • Loading branch information...
commit 4072568cdc251537fcb61306cda4efec444289f4 1 parent 027c3d1
Mislav Marohnić mislav authored

Showing 2 changed files with 18 additions and 1 deletion. Show diff stats Hide diff stats

  1. +7 1 lib/hub/commands.rb
  2. +11 0 test/hub_test.rb
8 lib/hub/commands.rb
@@ -970,7 +970,13 @@ def self.===(exception)
970 970
971 971 def display_http_exception(action, response)
972 972 $stderr.puts "Error #{action}: #{response.message} (HTTP #{response.code})"
973   - warn "Check your token configuration (`git config github.token`)" if response.code.to_i == 401
  973 + case response.code.to_i
  974 + when 401 then warn "Check your token configuration (`git config github.token`)"
  975 + when 422
  976 + if response.content_type =~ /\bjson\b/ and data = JSON.parse(response.body) and data["error"]
  977 + $stderr.puts data["error"]
  978 + end
  979 + end
974 980 end
975 981
976 982 end
11 test/hub_test.rb
@@ -882,6 +882,17 @@ def test_pullrequest_existing_issue_url
882 882 assert_output expected, "pull-request https://github.com/mojombo/hub/issues/92#comment_4"
883 883 end
884 884
  885 + def test_pullrequest_fails
  886 + stub_request(:post, "https://#{auth}github.com/api/v2/json/pulls/defunkt/hub").
  887 + to_return(:status => [422, "Unprocessable Entity"],
  888 + :headers => {"Content-type" => "application/json"},
  889 + :body => %({"error":["oh no!", "it failed."]}))
  890 +
  891 + expected = "Error creating pull request: Unprocessable Entity (HTTP 422)\n"
  892 + expected << "oh no!\nit failed.\n"
  893 + assert_output expected, "pull-request hereyougo -b feature -f"
  894 + end
  895 +
885 896 def test_checkout_no_changes
886 897 assert_forwarded "checkout master"
887 898 end

0 comments on commit 4072568

Please sign in to comment.
Something went wrong with that request. Please try again.