Cancelling any change in merge strategy with help of event handler in scriptrunner

With Bitbucket Server 4.9, repository admins can choose which merge strategies to allow, and set a default merge strategy.
The current, default, merge strategy ensures that merge commits are created after merging a pull request. These record the pull request number and branch name, helping to tie the merge back to a JIRA and a code review. Removing these commits may remove some valuable audit information.

We are trying to make an event handler ( repository modificationevent ) that will cancel the modification to repository if the merge strategy is changed from the default one .

We can also look at the possibility of hiding the UI web element of the merge strategies altogether.

 

Need some directions on this . 

Thanks


1 answer

1 accepted

This widget could not be displayed.

I looked at this and it appears when you change those merge strategies there is no cancellable event so you can't prevent them from being changed. It seems the only way around this for now is to hide the merge strategies using some JavaScript.

You can do this by using the "install web resource" Script Fragment in ScriptRunner for Bitbucket Server.

It should look like the screenshot below:

Screen Shot 2017-01-12 at 09.49.34.png

You will need to place the following JavaScript code in a file called hideMergeStrategies.js:

(function ($) {
    AJS.toInit(function () {
        var $mergeStrategiesHeader = $('h3:contains("Merge strategies")');
        // hide merge strategy header
        $mergeStrategiesHeader.hide();
        // hide merge strategy paragraph
        $mergeStrategiesHeader.parent().children('p').hide();
        // hide merge strategy options
        $('.merge-strategies').hide();
    });
})(AJS.$);

You will need to set the system property "plugin.resource.directories" to a particular directory if you haven't already and place the JavaScript file there.

Let us know how you get on with this or if you require further help.

Suggest an answer

Log in or Sign up to answer
Community showcase
Published Aug 21, 2018 in Bitbucket

Branch Management with Bitbucket

As a project manager, I have discovered that different developers want to bring their previous branching method with them when they join the team. Some developers are used to performing individual wo...

1,261 views 8 11
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