21

through the GitHub API, is it possible to get the number of open pull requests for a repository without downloading all the extra data related to the pull requests themselves?

For example, when you get the list of your repositories, for each of the repo you can see the number of open issues. Is there a similar property for open pull requests?

Simone Vicentini
  • 259
  • 1
  • 2
  • 7
  • My first answer was wrong as the search api keywords only match the content of the issue and the test I did was against an issue that contained the word "pull" in its description. So there is no way to filter for pull requests only. I ended up just using the Pull Requests API for each repo for the moment: http://developer.github.com/v3/pulls/#list-pull-requests not ideal as I just want to know the count of pull requests. – Simone Vicentini Oct 30 '12 at 15:27
  • I would change the title: .."get count of open pull requests"... As for the total number of pull requests, with indeed an approximation, I used this: https://api.github.com/repos/ ... &state=all&page=1&per_page=1 . I mean I guess the english is ok (I am not EN speaker), but my search for total number of landed here ;) – mariotti Nov 11 '18 at 16:16

2 Answers2

8

You might also take a look at the search api https://developer.github.com/v3/search/#search-issues. Looks like you can filter on type and probably also on closed or not :)

As suggested by codea in the comments:

https://api.github.com/search/issues?q=+type:pr+user:StackExchange&sort=created&order=asc 
Manuel van Rijn
  • 10,170
  • 1
  • 29
  • 52
  • 4
    `https://api.github.com/search/issues?q=+type:pr+user:StackExchange&sort=created&order=asc` – codea Dec 09 '15 at 13:45
  • how to overcome 30 hits limit? Is there a way to get each repo count in one for org in one hit. I tried below query but it gives count for all repos: `https://api.github.com/search/issues?q=+type:pr+org:orgName` – SS Sid Feb 05 '18 at 22:52
  • 1
    @ShahidSiddique take a look at https://developer.github.com/v3/#pagination – Manuel van Rijn Feb 06 '18 at 07:36
0

I used the Pulls Request API in combination with jq ability to count objects (see How to count items in JSON object using command line?)

With cURL:

curl https://api.github.com/repos/OWNER/REPO/pulls | jq length

With Github CLI

gh api \
  -H "Accept: application/vnd.github+json" \
  /repos/OWNER/REPO/pulls | jq length
Joker
  • 2,304
  • 25
  • 36