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

handle pull requests from private repos

上级 bc5e07c6
## master ## master
* handle pull requests from private repos
* support branches with slashes in their name * support branches with slashes in their name
* display server errors when creating pullrequest fails * display server errors when creating pullrequest fails
* support GitHub Enterprise via multiple whitelisted host names * support GitHub Enterprise via multiple whitelisted host names
......
...@@ -313,7 +313,9 @@ module Hub ...@@ -313,7 +313,9 @@ module Hub
args.before ['remote', 'set-branches', '--add', user, branch] args.before ['remote', 'set-branches', '--add', user, branch]
args.before ['fetch', user, "+refs/heads/#{branch}:refs/remotes/#{user}/#{branch}"] args.before ['fetch', user, "+refs/heads/#{branch}:refs/remotes/#{user}/#{branch}"]
else else
args.before ['remote', 'add', '-f', '-t', branch, user, github_project(url.project_name, user).git_url] url = github_project(url.project_name, user).git_url(:private => pull_data['head']['repository']['private'],
:https => https_protocol?)
args.before ['remote', 'add', '-f', '-t', branch, user, url]
end end
args[1..-1] = ['-b', new_branch_name, "#{user}/#{branch}"] args[1..-1] = ['-b', new_branch_name, "#{user}/#{branch}"]
end end
......
...@@ -906,6 +906,15 @@ class HubTest < Test::Unit::TestCase ...@@ -906,6 +906,15 @@ class HubTest < Test::Unit::TestCase
"checkout https://github.com/defunkt/hub/pull/73/files" "checkout https://github.com/defunkt/hub/pull/73/files"
end end
def test_checkout_private_pullrequest
stub_request(:get, "https://#{auth}github.com/api/v2/json/pulls/defunkt/hub/73").
to_return(:body => mock_pull_response('blueyed:feature', :private))
assert_commands 'git remote add -f -t feature blueyed git@github.com:blueyed/hub.git',
'git checkout -b blueyed-feature blueyed/feature',
"checkout https://github.com/defunkt/hub/pull/73/files"
end
def test_checkout_pullrequest_custom_branch def test_checkout_pullrequest_custom_branch
stub_request(:get, "https://#{auth}github.com/api/v2/json/pulls/defunkt/hub/73"). stub_request(:get, "https://#{auth}github.com/api/v2/json/pulls/defunkt/hub/73").
to_return(:body => mock_pull_response('blueyed:feature')) to_return(:body => mock_pull_response('blueyed:feature'))
...@@ -1311,8 +1320,8 @@ config ...@@ -1311,8 +1320,8 @@ config
%({"pull": { "html_url": "https://github.com/#{name_with_owner}/pull/#{id}" }}) %({"pull": { "html_url": "https://github.com/#{name_with_owner}/pull/#{id}" }})
end end
def mock_pull_response(label) def mock_pull_response(label, priv = false)
%({"pull": { "head": { "label": "#{label}" }}}) %({"pull": { "head": { "label": "#{label}", "repository": {"private":#{!!priv}} }}})
end end
def improved_help_text def improved_help_text
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册