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

Get branch details

Yogesh Mude
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.
October 27, 2020

How do I get the branch name and last commit date using a groovy script?

1 answer

0 votes
Robert Giddings [Adaptavist]
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
November 4, 2020

Hi @Yogesh Mude ,

Please can you tell me how you are using this groovy script?

Is it as a Pre Hook or Merge Check, for example? Or a script you want to run in the Console?

I ask, because knowing where and how the script will be run will affect the script example I can provide you.

Thanks,

Robert Giddings,

Product Manager, ScriptRunner for Bitbucket

Yogesh Mude
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.
November 4, 2020

Hello, @Robert Giddings [Adaptavist] ,

Thanks for the time and response.

Actually, we have a requirement like every Friday or once in a week bitbucket should send an email listing all open branches.

So for this, I checked in Script Runner there is a Jobs (ie. Schedule Custom Email) using which I can send an email based on the interval.

So here I need to write a script where I can get all detail like Project Name, Open branch Name,  Last commit date, Has open pull request or not, etc..

Can you guide me or provide me any previous script for assistance.

Regards,

Yogesh

Robert Giddings [Adaptavist]
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
November 12, 2020

Hi @Yogesh Mude ,

If you look at this Community post (https://community.atlassian.com/t5/Adaptavist-questions/Scriptrunner-list-of-tags/qaq-p/1376193) it has a Script on it, that reports on all tags belonging to a repository using the 

com.atlassian.bitbucket.repository.RefService.getTags()

method.

You could use that Script as a basis, but instead you would want to use the 

com.atlassian.bitbucket.repository.RefService.getBranches()

method. The results of which contain the last commit.

Here is the JavaDoc with the details of RefService: https://docs.atlassian.com/bitbucket-server/javadoc/6.9.0/api/com/atlassian/bitbucket/repository/RefService.html

Also, you will also want to use the PullRequestService in order to search for open Pull Requests.

Here is the JavaDoc with the details of the PullRequestService: https://docs.atlassian.com/bitbucket-server/javadoc/6.9.0/api/com/atlassian/bitbucket/pull/PullRequestService.html

Please let me know if you require any more help?

Kind regards,

Robert Giddings,

Product Manager, ScriptRunner for Bitbucket

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events