From 3b1a31f7cc9f8b33b52efe21eed651aae0636f4a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mislav=20Marohnic=CC=81?= Date: Wed, 21 Dec 2011 20:30:17 +0100 Subject: [PATCH] handle pull requests from private repos --- HISTORY.md | 1 + lib/hub/commands.rb | 4 +++- test/hub_test.rb | 13 +++++++++++-- 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/HISTORY.md b/HISTORY.md index c9d346b2..9e4c9532 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 00a2dfec..fd8bd03e 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 d457ab39..0ee08ee8 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 -- GitLab