Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to query review requests by user, using Github's v4 GraphQL API?

Given a user's id, I want to get all pull requests where they are a requested reviewer.

The following won't work as it only allows me to get pull requests opened by that user:

query {
  node(id: "$user") {
    ... on User {
      pullRequests(first: 100) {
        nodes {
          reviewRequests(first: 100) {
            nodes {
              requestedReviewer {
                ... on User {
                  id
                }
              }
            }
          }
        }
      }
    }
  }
}

Is there a way to do this?

Thanks!

like image 203
liszt Avatar asked Mar 07 '23 03:03

liszt


1 Answers

You can get username from the user id and perform a search with review-requested to match a user requested for review :

get username :

{
  node(id: "MDQ6VXNlcjk2OTQ3") {
    ... on User {
      login
    }
  }
}

get open PR where user is review requested :

{
  search(query: "type:pr state:open review-requested:refack", type: ISSUE, first: 100) {
    issueCount
    pageInfo {
      endCursor
      startCursor
    }
    edges {
      node {
        ... on PullRequest {
          repository {
            nameWithOwner
          }
          number
          url
        }
      }
    }
  }
}

You can define the query string as a variable, try it in the explorer

like image 56
Bertrand Martel Avatar answered Apr 27 '23 05:04

Bertrand Martel