How to prevent a pull request from being re-scoped after approval?


I noticed that after a pull request is being approved, a developer can push more changes to the branch without notifying the reviewer, and somehow those "unwanted" changes get merged.

Is there a way to "freeze" the branch in which the pull request was raised? I was thinking of writing a plugin which implements com.atlassian.bitbucket.event.pull.PullRequestParticipantApprovedEvent event, but I am not sure how to go from there.

Any pointers?


Thank you,


3 answers

1 accepted

1 vote
Accepted answer

Hi Faissal,

Is the goal just to prevent the new unapproved changes from getting merged? If so you have the following option with ScriptRunner for Bitbucket Server:

Using the withdraw approvals event handler for this purpose, which will withdraw approvals if a pull request is changed after the approval. See the docs here for how to use this. 

You can find it under Repository Settings -> Script Event Handlers -> "Withdraw approvals when a pull request changed" or Admin -> ScriptRunner -> Script Event Handlers -> "Withdraw approvals when a pull request changed"

You could then combine this with a merge check to check all users have approved the pull request or some number of them.

You can find it under Repository Settings -> Script Merge Checks -> "Custom merge check" or Admin -> ScriptRunner -> Script Merge Checks -> "Custom merge check"

The example below will check all reviewers have approved, which you need to copy as an inline script in the custom merge check:

import com.atlassian.bitbucket.scm.pull.MergeRequest

def mergeRequest = mergeRequest as MergeRequest

if (! mergeRequest.pullRequest.reviewers.every {it.approved}) {
    mergeRequest.veto("Not enough approvals", "All reviewers must approve before merge")

I think this solution is much better than adding a pre-receive hook to block the push and will also provide you flexibility to define your own conditions according to the development process each team has.

Although you can lookup writing your own pre-receive hook if thats what you really want using ScriptRunner here.

Let me know if you need any help with this or more details.

Hope this helps,

1 vote

Another option is to install the Bitbucket Server Auto Unapprove plugin, which will remove the approvals if someone pushes more changes to the pull request source branch.


You would want to write a little pre-receive hook that checks

  • if branch has outgoing PR(s)
  • If so - are there any approvals yet
  • If so - rejected the push to the branch. 

There are some good hook tutorials in 

Hope that helps

Suggest an answer

Log in or Sign up to answer
Community showcase
Published Nov 06, 2018 in Bitbucket

Upgrade Best Practices

Hello! My name is Mark Askew and I am a Premier Support Engineer for products Bitbucket Server/Data Center, Fisheye & Crucible. Today, I want to bring the discussion that Jennifer, Matt, and ...

1,955 views 7 10
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you