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,463,473
Community Members
 
Community Events
176
Community Groups

Conditional merge check: How to get content of .yml file and compare it with a specific group

Edited

Hi Folks, and especially @Robert Giddings _Adaptavist_ !

I'll split the global task in three smaler.

1. We need to read a content of .yml file that is located in the root. There we need to find a row with "verConfigRefs: - release/13.01.00.x" and after that get only the "13.01.00.x" value.

2. After that we need to check if a current user is a member of any group with pattern "13.01.00.x".

3. If Yes, we allow them to Merge.


I've found a solution or solved particularly for all small tasks and I need your precious help to combine them and get the final result.

With part 1 I found "Load content of JSON file from Pull Request" example. But I need to test it and have it worked. How can I use the similar code inside of Script Console to get Content of file and maybe to try to get the required parameter?

With part 2 I've checked these two scripts and them works. Could you check everything is ok?

This script to compare group name and prefix:

import java.util.regex.Matcher
import java.util.regex.Pattern
def text = "group_prefix"

Matcher m = text =~ /prefix/
if (m) {
true
}

 And this one to get list of user groups:

import com.atlassian.sal.api.component.ComponentLocator
import com.atlassian.bitbucket.user.UserService
import com.atlassian.bitbucket.auth.AuthenticationContext

import com.atlassian.crowd.manager.directory.DirectoryManager
import com.atlassian.crowd.search.query.entity.GroupQuery
import com.atlassian.crowd.model.group.GroupType
import com.atlassian.crowd.search.query.entity.restriction.TermRestriction
import com.atlassian.crowd.search.query.entity.restriction.PropertyImpl
import com.atlassian.crowd.search.query.entity.restriction.MatchMode
import com.atlassian.crowd.search.query.membership.MembershipQuery
import com.atlassian.crowd.search.builder.QueryBuilder
import com.atlassian.crowd.search.query.entity.UserQuery
import com.atlassian.crowd.search.EntityDescriptor
import com.atlassian.crowd.model.user.Users
import com.atlassian.crowd.model.group.Membership
import com.atlassian.bitbucket.user.UserSearchRequest
import com.atlassian.bitbucket.util.PageRequest
import com.atlassian.bitbucket.util.PageRequestImpl
import static com.onresolve.scriptrunner.canned.bitbucket.util.BitbucketCannedScriptUtils.unlimitedPager

def dm = ComponentLocator.getComponent(DirectoryManager)
def dir = dm.findAllDirectories().find {it.name == "Bitbucket Internal Directory"}?.id
def us = ComponentLocator.getComponent(UserService)

us.findGroupsByUser("slava", getUnlimitedPager()).values

One question here: Why findGroupsWithUser() function is not working for us? It allows to filter groups of user by specified name. And maybe with this function I could check if a user already a member of a group without matching strings. But it is not a blocker in final solution.

And with part 3 I already set the conditional merge check if user is a member of specific group then allow them to click on the Merge button.

 

To summarize: Could you help with a final script and to combine all the things above?

Thank you in advance!
With kind regards
Slava

1 answer

Hi @Slava Gefen ,

Thank you for your post.

There are quite a few things in there, so I'm going to suggest that you raise a Support Request with us at Adaptavist, in the first instance.

You can do this via our Support Portal for ScriptRunner for Bitbucket here: https://productsupport.adaptavist.com/servicedesk/customer/portal/3

Our Support team might be able to help you answer some of your questions. And if not, they will be able to advise you on what to do next.

Hope that helps?

Kind regards,

Robert Giddings,

Product Manager, ScriptRunner for Bitbucket

Thanks a lot @Robert Giddings _Adaptavist_ , I raised it.

So, I'll make this question as answered after the support team help me, ok?

Hi @Slava Gefen ,

Sounds good.

Kind regards,

Robert Giddings,

Product Manager, ScriptRunner for Bitbucket

Suggest an answer

Log in or Sign up to answer
TAGS

Atlassian Community Events