Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I get a list of all pull requests for a repo through the github API?

I want to obtain a list of all pull requests on a repo through the github API.

I've followed the instructions at http://developer.github.com/v3/pulls/ but when I query /repos/:owner/:repo/pulls it's consistently returning fewer pull requests than displayed on the website.

For example, when I query the torvalds/linux repo I get 9 open pull requests (there are 14 on the website). If I add ?state=closed I get a different set of 11 closed pull requests (the website shows around 20).

Does anyone know where this discrepancy arises, and if there's any way to get a complete list of pull requests for a repo through the API?

like image 510
ResearchMills Avatar asked Jul 02 '13 10:07

ResearchMills


People also ask

How do I fetch all GitHub repository?

How To List All Public Repositories Belonging to a User? So, to list all public repos from a user, send a GET request to https://api.github.com/users/<USER-NAME>/repos , replacing with the actual user from whom you want to retrieve the repositories.


3 Answers

You can get all pull requests (closed, opened, merged) through the variable state.

Just set state=all in the GET query, like this->

https://api.github.com/repos/:owner/:repo/pulls?state=all 

For more info: check the Parameters table at https://developer.github.com/v3/pulls/#list-pull-requests

Edit: As per Tomáš Votruba's comment:

the default value for, "per_page=30". The maximum is per_page=100. To get more than 100 results, you need to call it multiple itmes: "&page=1", "&page=2"...

like image 146
akshaynagpal Avatar answered Oct 03 '22 12:10

akshaynagpal


PyGithub (https://github.com/PyGithub/PyGithub), a Python library to access the GitHub API v3, enables you to get paginated resources.

For example,

g = Github(login_or_token=$YOUR_TOKEN, per_page=100) r = g.get_repo($REPO_NUMBER)  for pull in r.get_pulls('all'):     # You can access pulls 

See the documentation (http://pygithub.readthedocs.io/en/latest/index.html).

like image 39
Daisuke SHIBATO Avatar answered Oct 03 '22 12:10

Daisuke SHIBATO


With Github's new official CLI (command line interface):

gh pr list --repo OWNER/REPO

which would produce something like:

Showing 2 of 2 pull requests in OWNER/REPO

#62  Doing something    that-weird-branch-name
#58  My PR title        wasnt-inspired-branch

See additional details and options and installation instructions.

like image 44
Xavier Guihot Avatar answered Oct 03 '22 13:10

Xavier Guihot