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

ResearchMills picture ResearchMills · Jul 2, 2013 · Viewed 47k times · Source

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?

Answer

akshaynagpal picture akshaynagpal · Aug 1, 2016

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"...