Permalink
Browse files

handle pull requests from private repos

  • Loading branch information...
1 parent bc5e07c commit 3b1a31f7cc9f8b33b52efe21eed651aae0636f4a @mislav mislav committed Dec 21, 2011
Showing with 15 additions and 3 deletions.
  1. +1 −0 HISTORY.md
  2. +3 −1 lib/hub/commands.rb
  3. +11 −2 test/hub_test.rb
View
@@ -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
View
@@ -313,7 +313,9 @@ def checkout(args)
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
View
@@ -906,6 +906,15 @@ def test_checkout_pullrequest
"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 @@ def mock_pullreq_response(id, name_with_owner = 'defunkt/hub')
%({"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

0 comments on commit 3b1a31f

Please sign in to comment.