Github restapi: how to filter pulls requests by user?

Viewed 570

I'm trying to use the github REST api to get pull requests by user. I've read the docs and looked for examples and can't find clear directions how to do this. The basic .../pulls url works just fine - I get back a big list of pull requests. But when I try to filter to a user the way the docs seem to say, I just back an empty array.

I have verified:

  • The user names I am trying are correct- I have copied them from the pulls.user.login field
  • The users I am trying have pulls that show up in the .../pulls output

Here is what I have tried:

These attempts always return an empty array:
    [githost]/api/v3/repos/[owner]/[reponame]/pulls?head=user:myusername
    [githost]/api/v3/repos/[owner]/[reponame]/pulls?head=user:myusername&state=all
    [githost]/api/v3/repos/[owner]/[reponame]/pulls?head=user:myuserid
    [githost]/api/v3/repos/[owner]/[reponame]/pulls?head=user:myusername@mydomain

These desperate attempts always return the same output as .../pulls with no parameters
    [githost]/api/v3/repos/[owner]/[reponame]/pulls?head=myusername
    [githost]/api/v3/repos/[owner]/[reponame]/pulls?user=myusername

So what is the correct way to do this?

2 Answers

According to the GitHub,

Every pull request is an issue, but not every issue is a pull request.

So try this to get the list of all PRs created by a specific user:

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

Don't forget to replace my username 'genialkartik' with your username.

OK, I figured it out by using git's search api.

The query I used looks like this:

[githost]/api/v3/search/issues?per_page=50&q=type:pr+author:myusername

The results are little more terse than what .../pulls gives, but that's something I can work around.

Related