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...
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();
I'm getting an error trying to import the repo service. Do you know if it's deprecated or something?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.