Hi. I searched the plugin which will validate PullRequest. If a from branch is not rebased on to brach the plugin will disable "merge" button. But I did not found it
So I decided to make it. I started from scratch https://bitbucket.org/atlassian/stash-example-merge-check-config . but I cannot figure out how to check is from brach rebased on to branch. Can any body help?
Community moderators have prevented the ability to post new answers.
Hi Oleg,
I think what you really want to check is that the source branch has not fallen behind the target branch of the pull request. If it has then you should rebase otherwise there would be conflicts or the result of the merge will be unknown.
You can do this using ScriptRunner for Bitbucket Server. After installing you need to go to Admin -> ScriptRunner -> Script Merge Checks -> "Custom merge check" and for the inline script use the following:
import com.atlassian.bitbucket.scm.pull.MergeRequest import com.onresolve.scriptrunner.canned.bitbucket.pullrequests.PullRequestPolicies def mergeRequest = mergeRequest as MergeRequest def pullRequest = mergeRequest.pullRequest def pullRequestValidator = new PullRequestValidator() def isUpToDate = pullRequestValidator.isPullRequestUpToDate(pullRequest) if (! isUpToDate.shouldBeFFMerge) { mergeRequest.veto("Pull request is out of date!", "You must rebase this branch on the target branch first.") } class PullRequestValidator extends PullRequestPolicies { @Override String getName() { return null } @Override String getDescription() { return null } @Override List getParameters(Map params) { return null } @Override Map doScript(Map<String, Object> params) { return null } }
That will check if the source branch of the pull request is out of date with the target branch and if it is the merge button will be disabled.
The advantage of writing it like above is that you can change the error message the user receives when the merge button is greyed out.
You can also bulk select what repositories/projects to apply the check to as in the screenshot below:
Screen Shot 2017-02-07 at 11.40.09.png
Let me know how you get on with that or if you need further help getting it setup.
Its also useful to point out we have a version of this which blocks the creation of an out of date pull request here. Maybe you would like to add that in to your workflow as well.
Thanks,
Adam
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.