Reputation: 955
I need the list of reviewers for a PR, and the Review Requests API present in Github only provides me the requested reviewers which becomes empty once the reviewers have accepted their invitations. I also tried the Reviews API to get all reviews and then get unique users, but that seems to be only for users who enter one and not for those who have accepted the request review invitation and never posted a review.
Upvotes: 16
Views: 13138
Reputation: 3052
You need to combine both "reviews" and "requested reviews" to get a complete list of all reviews.
/repos/{owner}/{repo}/pulls/{pull_number}/reviews
/repos/{owner}/{repo}/pulls/{pull_number}/requested_reviewers
or, with the Octokit api:
const reviews = (
await octokit.rest.pulls.listReviews({
owner,
repo,
pull_number,
})
).data;
const requestedReviewers = (
await octokit.rest.pulls.listRequestedReviewers({
owner,
repo,
pull_number,
})
).data;
Upvotes: 1
Reputation: 806
It sounds like you're trying to use this in an automation like a GitHub Action, if this is the case, simply use this: https://github.com/marketplace/actions/get-github-pull-request-reviews
If not, you can simply fetch the reviews from the GitHub API like so:
https://api.github.com/repos/{AUTHOR}/{REPOSITORY}/pulls/{PULL_REQUEST_ID}/reviews
E.g: https://api.github.com/repos/bitcoin/bitcoin/pulls/29413/reviews
Only things to worry about then is the rate limits: https://docs.github.com/en/rest/using-the-rest-api/rate-limits-for-the-rest-api
Plan | Requests per hour |
---|---|
Unauthenticated | 50 |
Personal | 5000 |
Enterprise | 15000 |
Upvotes: 0
Reputation: 51
The way to get other reviewers is
https://api.github.com/repos/{owner}/{repo}/pulls/{pull_number}/reviews
You will get all actual reviews, and state
will show is it APPROVED
or CHANGES_REQUESTED
. And each review also has a user
Upvotes: 2
Reputation: 3713
Just went through this problem with the following solution.
According to GitHub's documentation:
GET /repos/:owner/:repo/pulls/:pull_number/requested_reviewers
Pull request authors and repository owners and collaborators can request a pull request review from anyone with write access to the repository. Each requested reviewer will receive a notification asking them to review the pull request.
Test Request:
https://api.github.com/repos/roliveiravictor/demo-rust-learning/pulls/1/requested_reviewers
Response:
{
"users": [],
"teams": []
}
Since nobody is settle on this public test repo, of course it's empty. Remember, they need to have write access on your repository. This worked pretty well on my private project.
Upvotes: 1