Hello,
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,
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,
Adam
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 must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You would want to write a little pre-receive hook that checks
There are some good hook tutorials in developer.atlassian.com.
Hope that helps
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.