Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Celebration

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

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,557,748
Community Members
 
Community Events
184
Community Groups

how to implement ScriptRunner for commit/pull request, merge check for complex branches in BitBucket

Edited

I am having a lot of issues or not understand enough about how to implement the pre-hook in BitBucket using ScriptRunner.  I have many but following are the first 3 cases:

we are using this kind of branching scheme:

develop/proj1/feature/[A-Z]{2,9}-\d+.*
develop/proj2/feature/[A-Z]{2,9}-\d+.*
develop/proj3/feature/[A-Z]{2,9}-\d+.*

release/proj1/feature/[A-Z]{2,9}-\d+.*
release/proj2/feature/[A-Z]{2,9}-\d+.*
release/proj3/feature/[A-Z]{2,9}-\d+.*

master/proj1/feature/[A-Z]{2,9}-\d+.*
master/proj2/feature/[A-Z]{2,9}-\d+.*
master/proj3/feature/[A-Z]{2,9}-\d+.*

The pre-hook for Branch and tag naming standards enforcement seems to work fine in the statement: master/feature/(proj1|proj2|proj3)/[A-Z]{2,9}-\d+.*

Case 1:
The Require commits to be associated with a valid Jira issue doesn't work in the JQL clause template: (issuetype = feature OR issuetype = Story OR issuetype = Bug OR issuetype = Sub-Task) AND (status = 'In Progress' OR status = 'In Review'))

Case 2: 
It also doesn't work for Require that pull request associated with a valid Jira issue:
Condition: (mergeRequest.pullRequest.fromRef.displayId.matches("release/.*") || mergeRequest.pullRequest.fromRef.displayId.matches("master/.*")) &&
!(mergeRequest.pullRequest.toRef.displayId.matches("develop/.*") || mergeRequest.pullRequest.toRef.displayId.matches("feature/.*"))

JQL clause template: issuetype = (issuetype = feature OR issuetype = Story OR issuetype = Bug OR issuetype = Sub-Task) AND (status = 'In Progress' OR status = 'In Review')
Case 3: 
Merge Check, how do I implement a check so that you can't only merge from develop/proj1 to /release/proj1 and /release/proj1 to /master/proj1 but can't not merge from proj1 to be or proj2 to proj3?
How do I make it work?  Is there a good tutorial somewhere or training that I can take?  Can we implement in bash or perl script and inject it to scriptRunner instead of using groovy?
Thank you.

1 answer

0 votes
Max Lim _Adaptavist_
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.
Dec 02, 2021 • edited

Cases 1. 2. Can I confirm if you already set up the Jira application link as documented in Adaptavist site?

Case 2. Following part of your condition:

mergeRequest.pullRequest.toRef.displayId.matches("feature/.*"))

probably should be: 

mergeRequest.pullRequest.toRef.displayId.matches(".*/feature/.*"))

Please note that: the condition is not for a condition to reject a pull request, instead it is a condition to check for valid Jira issue.

Case 3. You can create a "Conditional merge check" that use similar condition in your case (2). Just be mindful that: In your condition, "fromRef" refers to source branch, "toRef" refers to target branch.

I hope this helps.

Thank you so much for your response.

Case 1. 2. Yes, Jira application link was established and is working properly.

Case 2. I will try that to see if it will work; however, I think it may still not know the Jira issue information because of the complexity level of the branch.

For Case 3.  I did something like this it seems to work but I'm not sure if it's working correctly yet:

def toBranch = mergeRequest.pullRequest.toRef.displayId
def fromBranch = mergeRequest.pullRequest.fromRef.displayId

def str1 = toBranch.split('/')[1];
def str2 = fromBranch.split('/')[1];

if (str1 == str2) {
     return false;
} else {
     return true;
}

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events