Permalink
Browse files

add support for pagination

  • Loading branch information...
1 parent 9c25bab commit 11e3471509c28e46fbd1850bab5741f0afd37966 @jianli committed Nov 2, 2012
Showing with 13 additions and 9 deletions.
  1. +13 −9 lib/hub/github_api.rb
View
@@ -111,15 +111,19 @@ def create_pullrequest options
# 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
- }
+ 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 current_branch.short_name == x['head']['label'].split(':', 0)[1]
+ return x['html_url']
+ end
+ }
+ page += 1
+ end
nil
end

0 comments on commit 11e3471

Please sign in to comment.