Permalink
Browse files

search closed pull requests as well

  • Loading branch information...
1 parent e556d9f commit 8ca76ffca4f1096082380f11aa56eb77ee290522 @jianli committed Nov 9, 2012
Showing with 14 additions and 12 deletions.
  1. +14 −12 lib/hub/github_api.rb
View
@@ -111,18 +111,20 @@ def create_pullrequest options
# Return the pull request corresponding to the current branch
def get_pullrequest project, branch_name
- page = 1
- res = nil
- while page == 1 or res.data.length > 0
- res = get "https://%s/repos/%s/%s/pulls?page=%s" %
- [api_host(project.host), project.owner, project.name, page]
- res.error! unless res.success?
- res.data.each { |x|
- if branch_name == x['head']['label'].split(':', 0)[1]
- return x['html_url']
- end
- }
- page += 1
+ for state in ['open', 'closed']
+ page = 1
+ res = nil
+ while page == 1 or res.data.length > 0
+ res = get "https://%s/repos/%s/%s/pulls?state=%s&page=%s" %
+ [api_host(project.host), project.owner, project.name, state, page]
+ res.error! unless res.success?
+ res.data.each { |x|
+ if branch_name == x['head']['label'].split(':', 0)[1]
+ return x['html_url']
+ end
+ }
+ page += 1
+ end
end
nil
end

0 comments on commit 8ca76ff

Please sign in to comment.