You're on your way to the next level! Join the Kudos program to earn points and save your progress.
Level 1: Seed
25 / 150 points
Next: Root
1 badge earned
Challenges come and go, but your rewards stay with you. Do more to earn more!
What goes around comes around! Share the love by gifting kudos to your peers.
Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!
Join now to unlock these features and more
The ultimate task I need to perform is to extract the the commits that are made to a specific branch between two time points. This is quite easy to achieve with git CLI but I am limited to Bitbucket API v1.
Of course it's not a problem to get all commits:
<stash-url>/rest/api/1.0/projects/<proj_name>/repos/<repo_name>/commits?since=<start>&until=<end>
But then I have no branch context.
The only query that I can made successfully is to retrieve the latest commit of the branch:
<stash-url>/rest/api/1.0/projects/<proj_name>/repos/<repo_name>/commits?until=<branch_name>
Basically what I am missing is the ability to make a connection between a branch and a commit.
Any help will be appreciated.
Please try this. It gives the branch of a commit.
this api response only return the latest branch.
how can I get all the branches which contain this commit?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello Taras and welcome to the Community!
I research a bit on your question about linking commits to a specific Bitbucket branch and found there is a possible solution within the v1 API for Bitbucket Server. While the documentation is not exactly clear on how to accomplish this, I did find a community post where someone figured out how to do this along with a StackOverflow thread on a similar topic.
The StackOverflow thread reports the following may work for your needs:
https://<stash-url>/stash/rest/api/latest/projects/<project-ID>/repos/<repo-slug>/commits?until=<my-target-feature-branch>&limit=0&start=0
Source thread: I want to get commits on a branch in bitbucket stash via rest API
Along with this, the Community post reports the following also worked for their requirements (This is similar to your API call on getting the last commit):
http://<stashurl>/stash/rest/api/latest/projects/<projectname>/repos/<myrepo>/commits?until=deploy&limit=0&start=0
Source post: Querying the last commit on a particular branch in Bitbucket using the Rest API
From my understanding on this, you should be able to use the StackOverflow response to call against the feature branch within Bitbucket and have it return commits for the said branch. Please give this a try and let us know the results.
We look forward to hearing back from you so we may find a way to link Commits to Branches within Bitbucket Server.
Regards,
Stephen Sifers
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Stephen,
Unfortunately both solutions (which are in fact identical) produce the same outcome - the latest commit of the desired branch. Meaning that it leavens me with nothing to retrieve the other commits from the same branch.
I kind of found a partial solution by reverse engineering. Thus master branch commits always have their previous commit as a parent. Thus it is only a matter of traversing "parent->parent->parent..." until the required depth is reached. All these "parent" items are the commits of the master branch.
But this only works because in my case we have a strict policy of not committing to master directly and only merging feature branches instead.
Meaning that this problem cannot be solved reliably. Unfortunately.
Thank you Stephen anyway.
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.
Nope :o(
I am afraid this can only be achieved with the new/latest API but not with the legacy version.
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.