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,466,100
Community Members
 
Community Events
176
Community Groups

Get a list of branches based on branch type

Hi,

using the Bitbucket Rest API is there a way to filter the branches based on branch type ?

ex. I want to get the 'release' branches of a particular repository.

 

tried this API, but it is returning all the branches

https://api.bitbucket.org/2.0/repositories/{workspace}/{repo_slug}/refs/branches?branchtype=release

1 answer

1 accepted

0 votes
Answer accepted
Ben Atlassian Team Jul 21, 2022

Hey Asha,

Welcome to the Bitbucket Cloud Community! :)

The /2.0/repositories endpoint supports filtering/sorting based on the properties of the schema (this can be found in the JSON response).

For your case, the "name" property can be found in the JSON response, and thus can be filtered to find branches which begin with a certain string.

name ~ "release/"

When converted to unicode using escape characters to form the URL, this results in the following URL which can be queried with the GET method to provide this list for you:

https://api.bitbucket.org/2.0/repositories/{workspace}/{reposlug}/refs/branches/?q=name%20~%20%22release%2F%22

More information/instructions can be found here: https://developer.atlassian.com/cloud/bitbucket/rest/intro/#filtering

Hope this helps.

Cheers!

- Ben (Bitbucket Cloud Support)

Hey Ben,

 

I tried the API by filtering the branches by name as you suggested. API is fetching all branches starting with name release instead of active branches.

for ex., I have 50 branches out of which 10 branches are active. The API is getting a total of 50 branches instead of 10. Can you suggest an API/ filtering for this.

Hi Asha,

Unfortunately - as the API does not expose ahead/behind information, it is not possible to determine active branches based on the API call.

This has been logged with our development team accordingly, feel free to "Watch" this issue to receive updates related to it and "Vote" on this issue to improve the visibility of customer demand:
https://jira.atlassian.com/browse/BCLOUD-12592

You can run a git for-each-ref command to sort the committer date for each branch and pipe a grep command to only show release branches, this way you can cross-reference the API results and determine which branches should be considered and which should be ignored:

git for-each-ref --sort=-committerdate --format='%(committerdate:short) %(refname)' refs/heads refs/remotes | grep 'release/'

You can further filter this by adding the --count switch to get at most the specified number in your results eg --count=10


Hope this helps.

Cheers!

- Ben (Bitbucket Cloud Support)

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PERMISSIONS LEVEL
Site Admin
TAGS

Atlassian Community Events