diff --git a/features/authentication.feature b/features/authentication.feature index 8275cf7b4174df0d19bcfd40b18c1ea24b02441e..038d56027c0604bfc2acd687db4f28667e25b619 100644 --- a/features/authentication.feature +++ b/features/authentication.feature @@ -13,7 +13,9 @@ Feature: OAuth authentication halt 400 unless params[:scopes] == ['repo'] json :token => 'OTOKEN' } - post('/user/repos') { status 200 } + post('/user/repos') { + json :full_name => 'mislav/dotfiles' + } """ When I run `hub create` interactively When I type "mislav" @@ -36,7 +38,9 @@ Feature: OAuth authentication {:token => 'OTOKEN', :app => {:url => 'http://defunkt.io/hub/'}} ] } - post('/user/repos') { status 200 } + post('/user/repos') { + json :full_name => 'mislav/dotfiles' + } """ When I run `hub create` interactively When I type "mislav" @@ -56,7 +60,9 @@ Feature: OAuth authentication {:token => 'OTOKEN', :app => {:url => 'http://defunkt.io/hub/'}} ] } - post('/user/repos') { status 200 } + post('/user/repos') { + json :full_name => 'mislav/dotfiles' + } """ Given $GITHUB_USER is "mislav" And $GITHUB_PASSWORD is "kitty" diff --git a/features/create.feature b/features/create.feature index 960afdfce12019073adc514cacc34085667cfc2a..d0546f0accb510f812bdf53455b9a341c35cf056 100644 --- a/features/create.feature +++ b/features/create.feature @@ -8,7 +8,7 @@ Feature: hub create """ post('/user/repos') { halt 400 if params[:private] - status 200 + json :full_name => 'mislav/dotfiles' } """ When I successfully run `hub create` @@ -20,7 +20,7 @@ Feature: hub create """ post('/user/repos') { halt 400 unless params[:private] - status 200 + json :full_name => 'mislav/dotfiles' } """ When I successfully run `hub create -p` @@ -29,7 +29,9 @@ Feature: hub create Scenario: HTTPS is preferred Given the GitHub API server: """ - post('/user/repos') { status 200 } + post('/user/repos') { + json :full_name => 'mislav/dotfiles' + } """ And HTTPS is preferred When I successfully run `hub create` @@ -38,7 +40,9 @@ Feature: hub create Scenario: Create in organization Given the GitHub API server: """ - post('/orgs/acme/repos') { status 200 } + post('/orgs/acme/repos') { + json :full_name => 'acme/dotfiles' + } """ When I successfully run `hub create acme/dotfiles` Then the url for "origin" should be "git@github.com:acme/dotfiles.git" @@ -59,7 +63,7 @@ Feature: hub create """ post('/user/repos') { halt 400 unless params[:name] == 'myconfig' - status 200 + json :full_name => 'mislav/myconfig' } """ When I successfully run `hub create myconfig` @@ -71,7 +75,7 @@ Feature: hub create post('/user/repos') { halt 400 unless params[:description] == 'mydesc' and params[:homepage] == 'http://example.com' - status 200 + json :full_name => 'mislav/dotfiles' } """ When I successfully run `hub create -d mydesc -h http://example.com` @@ -86,7 +90,9 @@ Feature: hub create Scenario: Origin remote already exists Given the GitHub API server: """ - post('/user/repos') { status 200 } + post('/user/repos') { + json :full_name => 'mislav/dotfiles' + } """ And the "origin" remote has url "git://github.com/mislav/dotfiles.git" When I successfully run `hub create` @@ -100,3 +106,14 @@ Feature: hub create When I successfully run `hub create` Then the output should contain "mislav/dotfiles already exists on github.com\n" And the url for "origin" should be "git@github.com:mislav/dotfiles.git" + + Scenario: API response changes the clone URL + Given the GitHub API server: + """ + post('/user/repos') { + json :full_name => 'Mooslav/myconfig' + } + """ + When I successfully run `hub create` + Then the url for "origin" should be "git@github.com:Mooslav/myconfig.git" + And the output should contain exactly "created repository: Mooslav/myconfig\n" diff --git a/lib/hub/commands.rb b/lib/hub/commands.rb index ab5d6241368d0550fa8c2b63ef54cbb97ae04bf9..dfc51e03174fa08bfcc9b4464803fdb82b812daa 100644 --- a/lib/hub/commands.rb +++ b/lib/hub/commands.rb @@ -525,7 +525,10 @@ module Hub action = "set remote origin" else action = "created repository" - api_client.create_repo(new_project, options) unless args.noop? + unless args.noop? + repo_data = api_client.create_repo(new_project, options) + new_project = github_project(repo_data['full_name']) + end end url = new_project.git_url(:private => true, :https => https_protocol?) diff --git a/lib/hub/github_api.rb b/lib/hub/github_api.rb index 32eb3adcb02bc3da87d217eb6febba85ac6e01c7..8c4e1cc61d61a6c67c2d858f6727e22e875ae4a9 100644 --- a/lib/hub/github_api.rb +++ b/lib/hub/github_api.rb @@ -77,6 +77,7 @@ module Hub res = post "https://%s/user/repos" % api_host(project.host), params end res.error! unless res.success? + res.data end # Public: Fetch info about a pull request.