How do I get repository settings via ScriptRunner for Bitbucket Edited

Hi

I was hoping this would be a simple answer but I can't seem to find an example.  I am writing a custom script in ScriptRunner and I would like to get the name of the default Branch while handling a PullRequestMergedEvent.  It's really easy to get a Repository Object but I don't see a way from repository or RepositoryService on how to get a hold of Repository Details.  Any suggestions?

 

I have been able to get a Repository object via this line:

Repository repo = ((PullRequestMergedEvent)event).getRepository().getName();

 

And I have been able to get a repositry using RepositoryService

import com.atlassian.sal.api.component.ComponentLocator;
import com.atlassian.bitbucket.repository.RepositoryService;
import com.atlassian.bitbucket.repository.Repository;

def repositoryService = ComponentLocator.getComponent(RepositoryService.class)
Repository rep = repositoryService.getBySlug("up","myrepo");
return rep;

 

Ultimately What I want is to get the Defailt Branch as well as other properties like Transcode diffs etc...temp.jpg

 

1 answer

I was able to figure out part of my answer on how to get the Default Branch.  I'll keep digging on how to get the other items.

 

import com.atlassian.sal.api.component.ComponentLocator;
import com.atlassian.bitbucket.repository.RepositoryService;
import com.atlassian.bitbucket.repository.Repository;
import com.atlassian.bitbucket.repository.RefService
def repositoryService = ComponentLocator.getComponent(RepositoryService.class);
def refService = ComponentLocator.getComponent(RefService.class);

Repository rep = repositoryService.getBySlug("UP","myrepo");
int id = rep.getId();

return refService.getDefaultBranch(rep).getDisplayId();

Suggest an answer

Log in or Sign up to answer
Atlassian Community Anniversary

Happy Anniversary, Atlassian Community!

This community is celebrating its one-year anniversary and Atlassian co-founder Mike Cannon-Brookes has all the feels.

Read more
Community showcase
Piotr Plewa
Published Dec 27, 2017 in Bitbucket

Recipe: Deploying AWS Lambda functions with Bitbucket Pipelines

Bitbucket Pipelines helps me manage and automate a number of serverless deployments to AWS Lambda and this is how I do it. I'm building Node.js Lambda functions using node-lambda&nbsp...

2,008 views 1 5
Read article

Atlassian User Groups

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

Find a group

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

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you