Based on this api: https://docs.github.com/en/rest/reference/pulls#get-a-pull-request
could I use the state, mergable or rebaseable fields from the response to find out that some reviewer approved my PR.
I'm also specifically looking for usecase where if there is a minimum requirement of 2 approving reviews(as shown below in the image) and the pull request only has 1 approval, the state should still be non-approved and should return approved once there are at least 2 approving reviewers. Is there any field that I can use for this usecase?
You can get a single PR and check it's state and merged properties. If it's merged, then it's accepted. If it's closed and not merged it may be rejected. In fact it may be not rejected but closed by a creator.
Once the repository maintainer has approved a pull request, the developer's new updates in the forked repository are merged with the main project repository. The product is then updated with the new feature or bug fix, and can now be viewed by end users.
You can see the overall state of the last commit to a branch on your repository's branches page or in your repository's list of pull requests. If status checks are required for a repository, the required status checks must pass before you can merge your branch into the protected branch.
There are two options to do that.
APPROVE
and then use this advanced query syntax to search whether this PR was approved or not.Check this repository for complete code example (especially this function)
Using the GitHub GraphQL API you can query reviewDecision
on the pullRequest
field for a given repository.
If 2 reviews are required and the PR received exactly 1 approval, reviewDecision
will have the value REVIEW_REQUIRED
.
reviewDecision
is of type PullRequestReviewDecision, an enum with values of APPROVED
, CHANGES_REQUESTED
, and REVIEW_REQUIRED
.
Example query:
{
repository(name: "gatsby", owner: "gatsbyjs") {
pullRequest(number: 30371) {
title
reviewDecision
state
reviews(first: 100) {
nodes {
state
author {
login
}
}
}
}
}
}
Response:
{
"data": {
"repository": {
"pullRequest": {
"title": "chore(gatsby): don't terminate dev server if graphql wasn't imported from gatsby",
"reviewDecision": "APPROVED",
"state": "MERGED",
"reviews": {
"nodes": [
{
"state": "APPROVED",
"author": {
"login": "LekoArts"
}
}
]
}
}
}
}
}
Depending on your repo settings, it may be a bit convoluted to check if a PR has been approved (for instance reviewDecision
returns null
if reviews are not enforced and the PR has received one approval but another review has been requested and is pending). You may need to iterate through the reviews
to find what you need.
state
may also be useful. It's of type PullRequestReviewState, an enum with values of APPROVED
, CHANGES_REQUESTED
, COMMENTED
, DISMISSED
, and PENDING
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With