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
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.