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,300,030
Community Members
 
Community Events
165
Community Groups

Can we get all remote branches in a Repo which are not updated for more than 180 days?

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

1 answer

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.')



Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Published in Bitbucket

Git push size limits are coming to Bitbucket Cloud starting April 4th, 2022

Beginning on April 4th, we will be implementing push limits. This means that your push cannot be completed if it is over 3.5 GB. If you do attempt to complete a push that is over 3.5 GB, it will fail...

2,255 views 2 9
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you