30

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

6
  • 1
    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)? Commented Jul 1, 2013 at 20:19
  • @EmilLundberg the image suggests he took that himself and so I suspect the question is obviously about how he might do so programmatically. :) Commented Jul 3, 2013 at 2:10
  • @sigmavirus24 I don't follow... :o ...D'oh, perhaps I should've followed the link, that makes it quite clear. xD Commented Jul 3, 2013 at 7:20
  • No worries @EmilLundberg I read it twice just to be certain of what he was asking. I shouldn't have sounded so nonchalant. Commented Jul 3, 2013 at 13:29
  • @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. :) Commented Jul 3, 2013 at 14:00

3 Answers 3

26

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')
3
  • 1
    ahhhh i like that better Commented May 5, 2017 at 20:04
  • It works, but it's not that intuitive. It should be more straight forward than this, but I guess once you know it...
    – David Xia
    Commented May 6, 2017 at 12:33
  • 3
    By default it only shows first 30 results. But you can browse the others using per_page (max 100) and page query parameters. For example, api.github.com/search/…
    – Ilyich
    Commented Oct 11, 2020 at 13:43
14

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
      }
    }
  }
}
1
  • 1
    Just to add that the v4 API utilises the Relay spec, so you can do { viewer { } } instead of { user(login: "...") } to get the pullrequests of the currently auth-ed user.
    – stephen mc
    Commented Mar 28, 2019 at 9:46
10

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.

6
  • OK So when I ran api.github.com/issues on my profile, I got nothing in there. However, I've done pull requests before on the account i was logged in as. Any other ideas? Commented Jul 3, 2013 at 21:28
  • Can you try curl -u nddipiazza https://api.github.com/issues and tell me what you see after typing in your GitHub password? Also what language/framework/wrapper are you using to communicate with the API? Commented Jul 4, 2013 at 3:44
  • 1
    It gives me a [] - what does that mean? (besides the obvious, that i don't have any issues) Commented Jul 5, 2013 at 20:13
  • 1
    It means you're authenticating properly and as far as GitHub is concerned you have no issues. I'm out of my depth at this point frankly. You might be better off contacting GitHub Support. Be sure to put API in the title so it goes right to their API team. Commented Jul 6, 2013 at 2:27
  • 1
    I believe OP wants all PRs he created when he wrote "my pull requests." I don't think /issues or /user/issues does this. According to github.com API docs developer.github.com/enterprise/2.8/v3/issues/#list-issues, these "List all issues assigned ... to the authenticated user" not created.
    – David Xia
    Commented May 4, 2017 at 19:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.