20
votes

If you look at: http://developer.github.com/v3/pulls/ it shows you how to get pull requests for a given repository.

How do we get "my pull requests" from the GitHub API similar to the data displayed on the GitHub dashboard?

I need something like this

3
Do you want to get a list programmatically (as the "api" word in the title suggests) or open a view in the browser (as the image suggests)?Emil Lundberg
@EmilLundberg the image suggests he took that himself and so I suspect the question is obviously about how he might do so programmatically. :)Ian Stapleton Cordasco
@sigmavirus24 I don't follow... :o ...D'oh, perhaps I should've followed the link, that makes it quite clear. xDEmil Lundberg
No worries @EmilLundberg I read it twice just to be certain of what he was asking. I shouldn't have sounded so nonchalant.Ian Stapleton Cordasco
@sigmavirus24 Ah, of course, now I get what you mean! Guess I had my "skeptical/off-topic?" glasses on since I was on a little border patrol through newest at the time. :)Emil Lundberg

3 Answers

16
votes

I asked Github directly. A rep told me to use the search endpoint. Search for issues owned by you that are open and of type pr.

https://api.github.com/search/issues?q=state%3Aopen+author%3Adavidxia+type%3Apr

If you're using a python client lib like Pygithub you can do

issues = gh.search_issues('', state='open', author='davidxia', type='pr')
11
votes

You can also use GraphQL API v4 to get all your pull requests :

{
  user(login: "bertrandmartel") {
    pullRequests(first: 100, states: OPEN) {
      totalCount
      nodes {
        createdAt
        number
        title
      }
      pageInfo {
        hasNextPage
        endCursor
      }
    }
  }
}

Try it in the explorer

or using viewer :

{
  viewer {
    pullRequests(first: 100, states: OPEN) {
      totalCount
      nodes {
        createdAt
        number
        title
      }
      pageInfo {
        hasNextPage
        endCursor
      }
    }
  }
}
10
votes

First you have to realize that you must authenticate using either Basic Authentication or a token. Next you have to realize that there is no simple way to do this so you will have to be clever.

To be specific, if you probe https://api.github.com/issues, you'll notice that the issues there have a hash called pull_request which should have 3 URLs: html, diff, and patch. All three will be non-null if the issue is also a Pull Request. (Pro-tip: They're the same thing as far as GitHub is concerned…sort of.)

If you iterate over your issues and filter for ones where those attributes are not null, then you'll have your pull requests.