0

how do I retrieve all the reviewers in a pull request from Probot? I am using typescript. I am also listening on pull_request event type in Probot. I think I need to call context.github.pullRequests.getReview to get the list of reviewers, but since I am new to NodeJs and typescript, I am not sure how to invoke the below function. Any inputs?

Also, getReview accepts the parameter {owner:,repo:,number:, review_id:}, in my case I just have the pr_number.

 getReview(
      params: Github.PullRequestsGetReviewParams,
      callback?: Github.Callback<
        Github.Response<Github.PullRequestsGetReviewResponse>
      >
    ): Promise<Github.Response<Github.PullRequestsGetReviewResponse>>;
Shravan Ramamurthy
  • 3,896
  • 5
  • 30
  • 44
  • I tried `context.github.pullRequests.listReviewRequests(context.issue());`, but this will give reviewers added during PR creation. How do I get all the reviewers (added during PR creation, self-requested and also added by another reviewer, etc) – Shravan Ramamurthy Apr 12 '19 at 05:21
  • 1
    I agree that this is rather confusing. I tested the [List reviews on a pull request](https://developer.github.com/v3/pulls/reviews/#list-reviews-on-a-pull-request) endpoint but it only lists the requests, not the reviews that have been actually done. I would recommend to contact support about it, it might be a bug, or the documentation needs to be updated – Gregor Apr 12 '19 at 20:36

2 Answers2

0

As mentioned in my comment above, the List reviews on a pull request does not return the reviews, but instead the review requests.

I could not find a REST API endpoint, but you could send a GraphQL Request instead

    query {
        resource(url:"https://github.com/probot/probot/pull/870") {
            ... on PullRequest {
                title
                url
                reviews(first: 100) {
                    nodes {
                        author {
                            login
                        }
                    }
                }
            }
        }
    }

you can use the context.graphql method for that. See https://github.com/octokit/graphql.js for its API. Make sure you use the latest version of Probot (current 9.2.4)

Gregor
  • 2,325
  • 17
  • 27
0

For us, it is in the requestedReviewer object of reviewRequests using pullRequests query.

One thing to notices is the reviewer could be User or Team so we need to leverage the spread operator ... on User/Team for them to get different fields.

query {
  compass: repository(owner: "YourOrg", name: "YourRepo") {
    pullRequests(states: [OPEN], last: 10) {
      edges {
        node {
          title,
          updatedAt,
          url
          mergeable
          author {
            login
          },
          reviewRequests(first: 10) {
            nodes{
              requestedReviewer{
                ... on User {
                  userName: name
                  login                  
                }
                ... on Team {
                  teamName: name
                }
              },

            }
          }
        }
      }
    }
  }
}
LeOn - Han Li
  • 9,388
  • 1
  • 65
  • 59