53

Using the new pull request approval process in Github, if I approve a PR but then a dev pushes a new commit to that branch I'd want the PR to go back to the state it is in to start with (i.e. not approved).

At the moment it stays green but in reality there is code that hasn't been reviewed in the branch.

Force Hero
  • 2,674
  • 3
  • 19
  • 35

2 Answers2

52

On GitHub, navigate to the main page of the repository. Under your repository name, click Settings. In the left menu, click Branches. Select the branch you want to restrict using the drop-down menu.

Select Dismiss stale pull request approvals when new commits are pushed.

enter image description here

This dismisses a pull request approval review when a code-modifying commit is pushed to the branch.

Click Save changes.

Ref: https://help.github.com/articles/enabling-required-reviews-for-pull-requests/

Ε Г И І И О
  • 11,199
  • 1
  • 48
  • 63
  • 5
    Follow-up question: what exactly is a "code-modifying commit"? Is there some way to configure certain config files to be "ignored" when deciding whether to dismiss a review as stale? – Jeff Gran Mar 18 '19 at 15:54
  • 1
    @JeffGran None that I know of. It was basically about the merge commits which happen when you click "Update branch". It does not dismiss reviews as long as you have no severe conflicts. – Ε Г И І И О Mar 19 '19 at 06:46
  • Can dismiss the PR approval for the new commit changes, but keep it when merging from master branch? – Bassem Mamar Sep 24 '20 at 13:02
  • Does this also invalidate approval if the branch is rebased? – Alper Oct 20 '21 at 11:57
  • This is not available in private repos for free accounts. – DBear Apr 15 '22 at 12:57
  • Is there a way to do this but only when a PR is moved from draft PR to "Ready to Review" (normal PR)? – Matthew Dean May 24 '22 at 21:49
35

It's not clear from your question if you need this automatically done, or if a manual process is okay too.

In my case a manual solution was fine. We'll just rely on developers to use their judgment on whether a PR should be unapproved.

To manually unapprove a PR, you can go to the comments section where the approval is, and click "show all reviewers". Then choose Dismiss for each approved review.

Chris Garrett
  • 4,824
  • 1
  • 34
  • 49