How to retrieve PR reviewers with GraphQL API?

I’m trying to retrieve all reviewers on a PR, I did look at PullRequest schema but couldn’t find a way to get reviewers. I’ve an example PR @ https://github.com/baswaraj-malage/browser-stack-test/pull/2 with 3 reviewers. Just one reviewer added a review comment on the PR and I could get only that reviewer info. as response with below query. How do I read all reviewers and their review state?

Query:

{
  viewer() {
    pullRequests(first: 100, states: OPEN) {
      totalCount
      edges {
        node {
          ... on PullRequest {
            repository {
              nameWithOwner
            }
            number
            url
            reviews(last: 10) {
              totalCount
              nodes {
                author {
                  login
                }
              }
            }
          }
        }
      }
      pageInfo {
        hasNextPage
        endCursor
      }
    }
  }
}

Response:

{
“data”: {
“viewer”: {
“pullRequests”: {
“totalCount”: 1,
“edges”: [
{
“node”: {
“repository”: {
“nameWithOwner”: “baswaraj-malage/browser-stack-test”
},
“number”: 2,
“url”: “https://github.com/baswaraj-malage/browser-stack-test/pull/2”,
“reviews”: {
“totalCount”: 1,
“nodes”: [
{
“author”: {
“login”: “ravibm100”
}
}
]
}
}
}
],
“pageInfo”: {
“hasNextPage”: false,
“endCursor”: “Y3Vyc29yOnYyOpHOD7wvOQ==”
}
}
}
}
}

Hi @baswaraj-malage,

Thanks for being here! 

If you use the Pull Requests Preview, you should be able to run this query:

query ($owner: String!, $name: String!, $number: Int!) {
  repository(owner: $owner, name: $name) {
    pullRequest: issueOrPullRequest(number: $number) {
      __typename
      ... on PullRequest {
        reviewThreads(first: 100) {
          edges {
            node {
              comments(first: 10) {
                nodes {
                  pullRequestReview {
                    id
                  }
                  body
                }
              }
            }
          }
        }
      }
    }
  }
}

Thank you @AndreaGriffiths11  for your suggestion. However, I’m getting an error on reviewThreads.

Also, it does not help me for my use case. My requirement is very simple, I’m stating once again below.

I would like to retrieve all PRs based off the logged in user and more importantly reviewers added to each PR.

You can look @ https://github.com/baswaraj-malage/browser-stack-test/pull/2 and the screen print attached which might provide details for my question.

You can run below code at GraphQL explorer https://developer.github.com/v4/explorer/. Currently, it does list all PRs/reviews etc…Now, I would like get list of reviewers on that PR.

query{
  user(login:"baswaraj-malage") {
    pullRequests(first: 100, states: OPEN) {
      totalCount
      edges {
        node {
          ... on PullRequest {
            repository {
              nameWithOwner
            }
            number
            url
            reviews(last: 10) {
              totalCount
              nodes {
                author {
                  login
                }
              }
            }
          }
        }
      }
      pageInfo {
        hasNextPage
        endCursor
      }
    }
  }
}

List of reviewers on my PR which I would like to retrieve via Github GraphQL API.

Reviewers.PNG

Baswaraj

bump.

To see if anyone has any suggestions. I’m fine even with a github REST API which does provide reviewers/review status. 

You can use reviewRequests.

query{
  user(login:"baswaraj-malage") {
    pullRequests(first: 100, states: OPEN) {
      totalCount
      edges {
        node {
          ... on PullRequest {
            repository {
              nameWithOwner
            }
            number
            url
<font color="#FF0000">reviewRequests(first: 100) {</font>
<font color="#FF0000"> nodes {</font>
<font color="#FF0000"> requestedReviewer {</font>
<font color="#FF0000"> ... on User {</font>
<font color="#FF0000"> name</font>
<font color="#FF0000"> login</font>
<font color="#FF0000"> }</font>
<font color="#FF0000"> }</font>
<font color="#FF0000"> }</font>
<font color="#FF0000"> } </font> }
        }
      }
      pageInfo {
        hasNextPage
        endCursor
      }
    }
  }
}
1 Like