diff --git a/HISTORY.md b/HISTORY.md index c9d346b28b4f444bba2b06fba6b63995c1dcee9f..9e4c953245e4898c379010a5029e881cc4837e8c 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -1,5 +1,6 @@ ## master +* handle pull requests from private repos * support branches with slashes in their name * display server errors when creating pullrequest fails * support GitHub Enterprise via multiple whitelisted host names diff --git a/lib/hub/commands.rb b/lib/hub/commands.rb index 00a2dfec2f45924c15c82dca817155ec025895b2..fd8bd03e75a62426f51a1c2659216c2c5899af2b 100644 --- a/lib/hub/commands.rb +++ b/lib/hub/commands.rb @@ -313,7 +313,9 @@ module Hub args.before ['remote', 'set-branches', '--add', user, branch] args.before ['fetch', user, "+refs/heads/#{branch}:refs/remotes/#{user}/#{branch}"] 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 args[1..-1] = ['-b', new_branch_name, "#{user}/#{branch}"] end diff --git a/test/hub_test.rb b/test/hub_test.rb index d457ab392af23267fc5585c986be15f5b751f197..0ee08ee8f07fedaf971a8f926a3283b7dd7c514c 100644 --- a/test/hub_test.rb +++ b/test/hub_test.rb @@ -906,6 +906,15 @@ class HubTest < Test::Unit::TestCase "checkout https://github.com/defunkt/hub/pull/73/files" 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 stub_request(:get, "https://#{auth}github.com/api/v2/json/pulls/defunkt/hub/73"). to_return(:body => mock_pull_response('blueyed:feature')) @@ -1311,8 +1320,8 @@ config %({"pull": { "html_url": "https://github.com/#{name_with_owner}/pull/#{id}" }}) end - def mock_pull_response(label) - %({"pull": { "head": { "label": "#{label}" }}}) + def mock_pull_response(label, priv = false) + %({"pull": { "head": { "label": "#{label}", "repository": {"private":#{!!priv}} }}}) end def improved_help_text