Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get all open pull requests from an organisation using the Github API Ruby gem

For our organisation's dashboard, I'd like to keep a count of all the open PRs on all our repositories. At the moment, all I've got is to loop through all the repos, and count through all the open PRs on each repo like so (which often results in a rate limit error):

connection = Github.new oauth_token: MY_OAUTH_TOKEN

pulls = 0

connection.repos.list(:org => GITHUB_ORGANISATION).each do |repo|
  pulls += connection.pull_requests.list(:user => repo['owner']['login'], :repo => repo['name']).count
end 

I know there must be a nicer way round this. Any ideas? (short of screen scraping!)

like image 718
Pezholio Avatar asked Aug 13 '13 13:08

Pezholio


People also ask

How do I see all pull requests?

You can also find pull requests that you've been asked to review. At the top of any page, click Pull requests or Issues. Optionally, choose a filter or use the search bar to filter for more specific results.

What is a pull request API?

The Pull Request API allows you to list, view, edit, create, and even merge pull requests. Comments on pull requests can be managed via the Issue Comments API. Every pull request is an issue, but not every issue is a pull request.


1 Answers

OK, so I think I've cracked this now. Pull requests are issues, so I can get all issues, and loop through the issues like so:

pulls = 0
issues = connection.issues.list(:org => GITHUB_ORGANISATION, :filter => 'all', :auto_pagination => true)
issues.each do |issue|
  if issue["pull_request"]
    pulls += 1
  end
end

Once you remember that pull requests are issues too, everything just falls into place.

like image 133
Pezholio Avatar answered Nov 15 '22 07:11

Pezholio