From 2886114d0a679cbcf5c56bed50fc853d0c836a50 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mislav=20Marohnic=CC=81?= Date: Tue, 20 Mar 2012 21:14:42 +0100 Subject: [PATCH] better error message when `git create` fails Fixes #147 --- lib/hub/commands.rb | 2 +- test/hub_test.rb | 31 ++++++++++++++++++++++--------- 2 files changed, 23 insertions(+), 10 deletions(-) diff --git a/lib/hub/commands.rb b/lib/hub/commands.rb index 6c113f7f..98fcde04 100644 --- a/lib/hub/commands.rb +++ b/lib/hub/commands.rb @@ -924,7 +924,7 @@ help params['homepage'] = options[:homepage] if options[:homepage] load_net_http - response = http_post(project.api_create_url('yaml'), params) + response = http_post(project.api_create_url('json'), params) response.error! unless Net::HTTPSuccess === response end diff --git a/test/hub_test.rb b/test/hub_test.rb index 875027cf..1a7cff7e 100644 --- a/test/hub_test.rb +++ b/test/hub_test.rb @@ -589,7 +589,7 @@ class HubTest < Test::Unit::TestCase def test_create stub_no_remotes stub_nonexisting_fork('tpw') - stub_request(:post, "https://#{auth}github.com/api/v2/yaml/repos/create"). + stub_request(:post, "https://#{auth}github.com/api/v2/json/repos/create"). with(:body => { 'name' => 'hub' }) expected = "remote add -f origin git@github.com:tpw/hub.git\n" @@ -600,7 +600,7 @@ class HubTest < Test::Unit::TestCase def test_create_custom_name stub_no_remotes stub_nonexisting_fork('tpw', 'hubbub') - stub_request(:post, "https://#{auth}github.com/api/v2/yaml/repos/create"). + stub_request(:post, "https://#{auth}github.com/api/v2/json/repos/create"). with(:body => { 'name' => 'hubbub' }) expected = "remote add -f origin git@github.com:tpw/hubbub.git\n" @@ -611,7 +611,7 @@ class HubTest < Test::Unit::TestCase def test_create_in_organization stub_no_remotes stub_nonexisting_fork('acme', 'hubbub') - stub_request(:post, "https://#{auth}github.com/api/v2/yaml/repos/create"). + stub_request(:post, "https://#{auth}github.com/api/v2/json/repos/create"). with(:body => { 'name' => 'acme/hubbub' }) expected = "remote add -f origin git@github.com:acme/hubbub.git\n" @@ -625,7 +625,7 @@ class HubTest < Test::Unit::TestCase stub_request(:get, "http://#{auth}github.com/api/v2/yaml/repos/show/tpw/hub"). to_return(:status => 404) - stub_request(:post, "http://#{auth}github.com/api/v2/yaml/repos/create"). + stub_request(:post, "http://#{auth}github.com/api/v2/json/repos/create"). with(:body => { 'name' => 'hub' }) expected = "remote add -f origin git@github.com:tpw/hub.git\n" @@ -641,7 +641,7 @@ class HubTest < Test::Unit::TestCase def test_create_failed stub_no_remotes stub_nonexisting_fork('tpw') - stub_request(:post, "https://#{auth}github.com/api/v2/yaml/repos/create"). + stub_request(:post, "https://#{auth}github.com/api/v2/json/repos/create"). to_return(:status => [401, "Your token is fail"]) expected = "Error creating repository: Your token is fail (HTTP 401)\n" @@ -660,7 +660,7 @@ class HubTest < Test::Unit::TestCase stub_request(:get, "https://#{auth('mojombo', '123abc')}github.com/api/v2/yaml/repos/show/mojombo/hub"). to_return(:status => 404) - stub_request(:post, "https://#{auth('mojombo', '123abc')}github.com/api/v2/yaml/repos/create"). + stub_request(:post, "https://#{auth('mojombo', '123abc')}github.com/api/v2/json/repos/create"). with(:body => { 'name' => 'hub' }) expected = "remote add -f origin git@github.com:mojombo/hub.git\n" @@ -675,7 +675,7 @@ class HubTest < Test::Unit::TestCase def test_create_private_repository stub_no_remotes stub_nonexisting_fork('tpw') - stub_request(:post, "https://#{auth}github.com/api/v2/yaml/repos/create"). + stub_request(:post, "https://#{auth}github.com/api/v2/json/repos/create"). with(:body => { 'name' => 'hub', 'public' => '0' }) expected = "remote add -f origin git@github.com:tpw/hub.git\n" @@ -683,10 +683,23 @@ class HubTest < Test::Unit::TestCase assert_equal expected, hub("create -p") { ENV['GIT'] = 'echo' } end + def test_create_private_repository_fails + stub_no_remotes + stub_nonexisting_fork('tpw') + stub_request(:post, "https://#{auth}github.com/api/v2/json/repos/create"). + to_return(:status => [422, "Unprocessable Entity"], + :headers => {"Content-type" => "application/json"}, + :body => %({"error":"repository creation failed: You are over your quota."})) + + expected = "Error creating repository: Unprocessable Entity (HTTP 422)\n" + expected << "repository creation failed: You are over your quota.\n" + assert_equal expected, hub("create -p") { ENV['GIT'] = 'echo' } + end + def test_create_with_description_and_homepage stub_no_remotes stub_nonexisting_fork('tpw') - stub_request(:post, "https://#{auth}github.com/api/v2/yaml/repos/create").with(:body => { + stub_request(:post, "https://#{auth}github.com/api/v2/json/repos/create").with(:body => { 'name' => 'hub', 'description' => 'toyproject', 'homepage' => 'http://example.com' }) @@ -736,7 +749,7 @@ class HubTest < Test::Unit::TestCase def test_create_origin_already_exists stub_nonexisting_fork('tpw') - stub_request(:post, "https://#{auth}github.com/api/v2/yaml/repos/create"). + stub_request(:post, "https://#{auth}github.com/api/v2/json/repos/create"). with(:body => { 'name' => 'hub' }) expected = "remote -v\ncreated repository: tpw/hub\n" -- GitLab