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

1 vote

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
How to earn badges on the Atlassian Community

How to earn badges on the Atlassian Community

Badges are a great way to show off community activity, whether you’re a newbie or a Champion.

Learn more
Community showcase
Posted Jun 12, 2018 in Bitbucket

Do you use any Atlassian products for your personal projects?

After spinning my wheels trying to get organized enough to write a book for National Novel Writing Month (NaNoWriMo) I took my affinity for Atlassian products from my work life and decided to tr...

31,059 views 26 12
Join discussion

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