10
votes

I just want to query the PRs from a specific user.

Do I need to use the head param? But how?

https://api.github.com/repos/org-a/repo-b/pulls?state=open&per_page=1&head=owner:user-c does not work.

API Refer: https://developer.github.com/v3/pulls/#list-pull-requests

2
The head param is quite poorly documented and as such is not particularly useful - I was able to get it to work in GitHub Enterprise by passing head=MyOrg:BranchName but that gave me one pull request - the pull request for that branch.tschumann

2 Answers

13
votes

Use the Search API and specify repo:REPO, author:USER and is:pr filters:

https://developer.github.com/v3/search/#search-issues-and-pull-requests

For example, here are the pull requests from rails/rails from aderyabin:

https://api.github.com/search/issues?q=is:pr+repo:rails/rails+author:aderyabin

0
votes

Here is the GraphQL API syntax to query the pull requests in the repo rails/rails from the author aderyabin:

{
  search(query: "is:pr author:aderyabin repo:rails/rails", type: ISSUE, first: 100) {
    issueCount
    edges {
      node {
        ... on PullRequest {
          title
          createdAt
          url
        }
      }
    }
  }
}

The PullRequest object docs lists the fields available to query.

It doesn't seem to be possible at the moment to filter a user's PR for a given repo (or a repo's PR for a given user), but the same result can be achieved with the search query above.