I would like to leverage Bitbucket api to get all remote branches(including merged and unmerged) in a repo which have not been updated for more than 180 days
Hey Sudheer! It definitely looks like what you're wanting to do is possible with just 2 API endpoints. You'd need to first iterate through the values (repos) provided from the /2.0/repositories/{workspace} endpoint to get a list of your repos and their respective repo-slugs. Once you've got that, you can pass the slug into the /2.0/repositories/{workspace}/{repo-slug}/refs/branches endpoint to get details on the last updated timestamp. Then you simply need to compare the timestamps with whatever date/time you wish.
At a super high level this would look like the following in python:
def repos():
# https://developer.atlassian.com/bitbucket/api/2/reference/resource/repositories/%7Bworkspace%7D
yield repo.get('name), repo.get('slug')
def branches(repo):
# https://developer.atlassian.com/bitbucket/api/2/reference/resource/repositories/%7Bworkspace%7D/%7Brepo_slug%7D/refs/branches
yield branch.get('name'), branch.get('target').get('date')
def main():
for repo_name, repo_slug in repos():
for branch_name, branch_date in branches(repo_slug):
if branch_date < desired_date: #less than == older than
print(f'{branch_name} on {repo_name} is older than desired.')
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.