I would like to know if there is an function in the Github API which would return the status of a pull request whether its accepted or rejected. Does such a function exist?
About pull request reviews - GitHub Docs Reviews allow collaborators to comment on the changes proposed in pull requests, approve the changes, or request further changes before the pull request is merged. Repository administrators can require that all pull requests are approved before being merged. Skip to main content GitHub Docs All products
On the pull request, click Files changed . Review the changes in the pull request, and optionally, comment on specific lines. Above the changed code, click Review changes . Type a comment summarizing your feedback on the proposed changes. Select Approve to approve merging the changes proposed in the pull request. Click Submit review.
Once the pull request is opened, it cannot be approved by it’s creator. You must submit it to a peer for review and approval. So, for open-source contributions, there will be at least three repositories you must be aware of: the original repo, your GitHub fork, and your local repository.
The GitHub integration in GitKraken makes it easy to create a GitHub pull request. Get started by clicking the green + button from the PULL REQUESTS pane in the left panel. Next, you will drag-and-drop the branch you wish to merge from onto the branch you wish to merge to directly from the central graph.
I was stymied by this problem, too. I had a hard time finding relevant info in the docs.
Option A
The tactic I've landed on is to use the issues search endpoint with the review
qualifier in the q
param.
So, in my case, when I want to see all PRs assigned to me that have not yet been reviewed, I'd hit this endpoint: https://github.com/api/v3/search/issues?q=is:open+is:pr+review-requested:jordan-bonitatis+review:none
Other review
qualifiers include approved
and changes_requested
as explained here: https://docs.github.com/en/github/searching-for-information-on-github/searching-issues-and-pull-requests#search-by-pull-request-review-status-and-reviewer
Option B
If you want to see the review status for a given PR, instead of getting a list filtered by status like in my example above, you can hit the pull requests reviews endpoint: /repos/:owner/:repo/pulls/:number/reviews
This will return a list of reviews for the PR, each of which have a state
key.
Note that a given PR may have multiple reviews with conflicting states. Like, if teamMemberA approved it but teamMemberB requested changes. You'll have to traverse the entire list and decide how you want to treat it based on all the states.
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. I'm not sure if it's possible to check if it was closed by another user (rejected) or by it's creator (denied).
I had a similar requirement - to know if a PR has been approved or not before merging it to master. I added a rule on the repo to ensure that every PR must be approved prior to merging. Then on using the API to get details about the branch there was one field which stated if the branch was clean to merge or blocked . I used this as a way to mange things in my app.
mergeable_state
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