提交 d91214c4 编写于 作者: M Mislav Marohnić

`create` command uses API response to assign remote URL

This ensures we end up with the correct capitalization of user's login
name, and gives the opportunity to the server to change the project name
without having us choke on it.

Fixes #263
上级 8d50224e
......@@ -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"
......
......@@ -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"
......@@ -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?)
......
......@@ -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.
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册