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

Devtools_Barclays January 10, 2017

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
Answer accepted
adammarkham
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
January 11, 2017

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
TAGS
AUG Leaders

Atlassian Community Events