Permalink
Browse files

add the pull-request -l flag to print pull request URLs

  • Loading branch information...
jianli committed Nov 2, 2012
1 parent 7939de4 commit 9c25bab3709bf00aa214fe38c2bd3efd0e5462d9
Showing with 20 additions and 0 deletions.
  1. +6 −0 lib/hub/commands.rb
  2. +14 −0 lib/hub/github_api.rb
View
@@ -95,6 +95,12 @@ def pull_request(args)
while arg = args.shift
case arg
+ when '-l'
+ pull_data = api_client.get_pullrequest(base_project, current_branch)
+ if pull_data
+ puts pull_data
+ end
+ exit
when '-f'
force = true
when '-b'
View
@@ -109,6 +109,20 @@ def create_pullrequest options
res.data
end
+ # Return the pull request corresponding to the current branch
+ def get_pullrequest project, current_branch
+ res = get "https://%s/repos/%s/%s/pulls" %
+ [api_host(project.host), project.owner, project.name]
+ puts res.data.length
+ res.error! unless res.success?
+ res.data.each { |x|
+ if current_branch.short_name == x['head']['label'].split(':', 0)[1]
+ return x['html_url']
+ end
+ }
+ nil
+ end
+
# Methods for performing HTTP requests
#
# Requires access to a `config` object that implements `proxy_uri(with_ssl)`

0 comments on commit 9c25bab

Please sign in to comment.