AndreDurao
AndreDurao

Reputation: 5795

Filter PullRequest by assignee or tags on Github API

there!

I'm using Github API to get the list of pull requests on a repo;

My auth token is valid and I'm receiving a valid JSON response from Github

curl -H "Authorization: token MY_AUTH_TOKEN" https://api.github.com/repos/my_org/their_repo/pulls

I'm following their docs on: https://developer.github.com/v3/pulls/

But I'm also interested in filter the pull requests by the user login just like Github does when we are using it on the browser

Example: https://github.com/rails/rails/pulls/assigned/dhh

I've tried both URLs:

https://api.github.com/repos/my_org/their_repo/pulls/assigned/_login_

and

https://api.github.com/repos/my_org/their_repo/pulls?assigned=_login_

But I couldn't find how to filter the list using the assignee or tags.

I found in the docs just the params: state, head, base, sort and direction.

How to filter the pull request using this options (tags or assignees)?

Upvotes: 3

Views: 1409

Answers (1)

Bertrand Martel
Bertrand Martel

Reputation: 45432

Using Github API v3

You can use Github Search issues API :

curl -s "https://api.github.com/search/issues?q=is:open%20is:pr%20assignee:dhh%20repo:rails/rails"

or using --data-urlencode :

curl -s -G "https://api.github.com/search/issues" \
     --data-urlencode "q=is:open is:pr assignee:dhh repo:rails/rails" | \
     jq '.'

Using Github GraphQL API v4

You can use the search query like this :

{
  search(query: "is:open is:pr assignee:dhh repo:rails/rails", type: ISSUE, first: 100) {
    issueCount
    edges {
      node {
        ... on PullRequest {
          number
          createdAt
          title
          headRef {
            name
            repository {
              nameWithOwner
            }
          }
          body
        }
      }
    }
  }
}

Try it in the explorer

Using & :

curl -s -H "Authorization: bearer YOUR_TOKEN" -d '
{
    "query": "query { search(query: \"is:open is:pr assignee:dhh repo:rails/rails\", type: ISSUE, first: 100) { issueCount edges { node { ... on PullRequest { number createdAt title headRef { name repository { nameWithOwner } } body } } } } }"
}
' https://api.github.com/graphql | jq '.'

Upvotes: 4

Related Questions