Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,298,096
Community Members
 
Community Events
165
Community Groups

Check whether source branch has fallen behind target branch

Hello,

my company is using Bitbucket Server v6.10.5 with ScriptRunner for Bitbucket v6.6.0.

I would like to create a "Conditional merge check" based on the accepted answer from this post:
https://community.atlassian.com/t5/Answers-Developer-Questions/Validate-PullRequest/qaq-p/536378

My goal is simply to check whether the source branch of an open pull request has maybe already fallen behind the target branch and if so, disable the merge button with a custom veto message.

When I use the code provided in the answer from the link above, I always get the error message: "unable to resolve class com.onresolve.scriptrunner.canned.bitbucket.pullrequests.PullRequestPolicies".

Unbenannt.JPG

Is anyone able to explain that error and/or how the solution needs to be adjusted so that it works for me?

Thanks a lot in advance
Sascha

1 answer

1 accepted

0 votes
Answer accepted

Hi @Sascha SK ,

ScriptRunner for Bitbucket now comes with a Built-In Merge Check for doing exactly that.

Please view the docs here, for info on the "Prevent Merge of Pull Requests Behind Target Branch" Built-In Merge Check: 

https://docs.adaptavist.com/sr4bib/latest/features/script-merge-checks/built-in-merge-checks/prevent-merge-of-pull-requests-behind-target-branch

However you will need to update to at least ScriptRunner for Bitbucket 6.28.0 in order to use it.

Please let me know if this works for you, without needing to write your own custom script?

Kind regards,

Robert Giddings,

Product Manager, ScriptRunner for Bitbucket

Hi @Robert Giddings _Adaptavist_ 

thanks a lot for your quick reply.

I will then request the required update to the version you mentioned (or higher) from the responsible team in my company and then let you know a bit later how it went.

Best regards
Sascha

Hi @Robert Giddings _Adaptavist_ ,

just FYI, the update to the newer version went fine and the new merge check is indeed exactly what we wanted. Thanks again for the hint.

The only unfortunate thing is the predefined veto message which cannot be changed. It always says by default

Please rebase your branch on to the target branch before merging a pull request: git checkout develop; git pull; git checkout feature/<branch-name>; git rebase develop; git push --force-with-lease

although even in the ScriptRunner docs it is mentioned that this is only one of the two solutions besides just merging the target branch into the source branch (so without any rebase). Maybe this can be improved in future versions since it's confusing to developers if rebasing is not the approach that is aimed for.

Best regards
Sascha

Hi @Sascha SK ,

Thank you for your latest comment.

And custom merge check messages is something we are indeed planning to add to the product in the near future.

Kind regards,

Robert Giddings

Like Sascha SK likes this

Hi @Robert Giddings _Adaptavist_ ,

after the first few days working with the hook mentioned above it turns out that the problem I described above (predefined veto message cannot be changed) is indeed quite critical for us since several developers - although they got a proper instruction - already got confused by it (we do not want to use rebasing but merging instead).

Do you see any chance to support me with the implementation of a "Conditional merge check" so I am able to add a custom veto message? I already gave that a try (see my very first post) but did not make it to get it running. Please also note that I am "only" admin as a Bitbucket user, so only able to access the ScriptRunner UI in my Bitbucket projects.

Thanks in advance and best regards
Sascha

@Robert Giddings _Adaptavist_ ,

are you meanwhile able to give at least a rough time frame for the custom veta messages built in by default in the hook mentioned above?

And custom merge check messages is something we are indeed planning to add to the product in the near future.

Thanks in advance and best regards
Sascha

Hi @Sascha SK ,

We plan to release custom messages sometime in the next month. I hope you are able to hold on until then?

Kind regards,

Robert Giddings

Hi @Sascha SK ,

We should be releasing an improvement to this merge-check's default message in the next ScriptRunner for Bitbucket release in about a weeks time.

Kind regards,

Robert Giddings

Hi @Sascha SK ,

We have now released a new version of ScriptRunner for Bitbucket with a more generalised Merge-Check message.

Please see the Release Notes for ScriptRunner for Bitbucket 6.41.0, for more details: https://docs.adaptavist.com/sr4bib/6.41.0/release-notes/release-6-x#id-.Release6.xv6.41.0

Please let me know if this helps resolve the issue previously reported above?

Kind regards,

Robert Giddings,

Product Manager, ScriptRunner for Bitbucket

@Robert Giddings _Adaptavist_ ,

thanks a lot for letting me know. Unfortunately, I have to admit that I'm a bit disappointed of this change. 

The corresponding ticket at https://productsupport.adaptavist.com/browse/SRBITB-1063 is correctly saying

This could confuse developers from teams that prefer following the merge strategy.

and instead of offering a custom veto message like with other already existing hooks (and like discussed in this conversation here), the already confusing default veto message was now just changed to yet another confusing default veto message. 

If my project only follows the merge strategy, it's still confusing to developers if both solutions (merging and rebasing) are offered in the message as equal alternatives. Instead, I would have loved to define a custom message saying "...please merge..." without mentioning rebasing only a bit.

Anyway, thanks again for letting me know and maybe there will be another change of this hook in the future with a real custom veto message.

Best regards
Sascha

Hi @Sascha SK ,

Thank you for your feedback.

Yes, the original intention was to make the message completely customisable. However, there are a few things we need to consider to make that work completely as expected.

So, in the meantime, we decided to make the error message more generic.

Given the above feedback, one possible improvement, prior to a completely custom message, might be to have a checkbox for selecting which of the two current messages you wanted?

We will look further into this.

Kind regards,

Robert Giddings,

Product Manager, ScriptRunner for Bitbucket

Hi @Robert Giddings _Adaptavist_ ,

thanks for your understanding and the explanation of the reasons.

If you really want to implement such an intermediate solution as described by you above, it would of course be very helpful if all three potential messages (only merging, only rebasing, both as equal alternatives) are also offered via checkbox(es)/dropdown(s)/etc.

Something like that would definitely be helpful to cover the time until a real custom veto message is available in that hook.

Best regards
Sascha

Hi @Sascha SK ,

I wanted to let you know that the latest version of ScriptRunner for Bitbucket, version 6.49.0, now has the option to configure which message will be displayed to users.

I.e. either telling the users to merge, or rebase, or that the users can do either.

Please let me know if this helps improve your development workflow?

Kind regards,

Robert Giddings,

Product Manager, ScriptRunner for Bitbucket

Hi @Robert Giddings _Adaptavist_ ,

thanks a lot for letting me know. I requested the version update with my IT and try to give it a try asap. It definitely sounds very promising ;-)

Best regards
Sascha

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Published in Bitbucket

Git push size limits are coming to Bitbucket Cloud starting April 4th, 2022

Beginning on April 4th, we will be implementing push limits. This means that your push cannot be completed if it is over 3.5 GB. If you do attempt to complete a push that is over 3.5 GB, it will fail...

2,223 views 2 9
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you