In short, it doesn't look like there's any straightforward way to get that particular data (latest branches).
Doing it on your own
First thing to think about is whether this type of data can be extracted at all.
In git
, a branch is just a label that points to a commit in the repository. In git
lingo, it's a ref
, as are tag
s. A branch
is different from a tag
in some ways, one being that the branch is always updated to point to the latest commit, as long as said branch is checked out (you're on that branch).
Branches themselves are only commit hash, and don't have any other properties such as creation date, or when it was last updated. To see this, try going through the files in the .git
file system directory from a repo; they're in ./git/refs/heads/
.
Having said that, there are some ways of guessing when the branch was first created, like explained in How to determine when a Git branch was created?, but this is outside the scope of Bitbucket's public API.
Doing it via the API
I suggest you make some direct API queries with curl
or Postman, in order to get a feel of what data is available. Looking over the actual API, and not the wrapper that you are using, it seems that the endpoint that you are using is /{workspace}/{repo_slug}/refs/branches/
. This seems to return you all the active branches, with 10 results per page, in the order in which git
itself returns them, and without any obvious way of requesting a sorted set. To break it down, there's
- active branches - seems like the a match for the data that you want;
- 10 per page - this means that you would have to make more requests until you get them all; in the response body there should be a
next
property`, holding the URL of the next set of results;
- no apparent way for the API to sort them - this means that you need to do some processing on your end. Once you get the data, you can dig deeper and find the dates, then sort them as you need.
Another way
The previous method would make the queries every time the program is ran. If you need something closer to realtime, you could set up a webhook to fire on each commit. A webhook is just a program that runs when a URL is requested; you hook it to some other system firing events. Once a commit is pushed, the webhook is called with the commit info, e.g. date, branch. Then you can store them, something like { "branch1": "1590406741", "branch2": "1590406441"}
.
Bitbucket webhooks
To sum up, there are some ways to achieve that, but you will need to do some extra coding to do.