Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

How can I efficiently get the number of commits a branch is ahead/behind using the REST API?

Adrian Price
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
April 25, 2017 edited

I'm trying to build reporting around branches' relative histories, so that we can:

  • See what branches have been merged to the upstream branch and can be removed
  • See what branches have commits that need to be merged to the upstream branch
  • See what branches need to be merged from upstream in order to avoid conflicts when merging to upstream

Basically I want the same ahead/behind info that's shown in the Web UI's Branches page for a repo, but I need to automate reporting on it for multiple repositories at once.

Right now I have a working process via:

  1. Get list of repos
  2. For each repo, get list of branches
  3. For each branch, get list of commits on that branch with ?exclude=<upstream> to see how many commits ahead it is
  4. For each branch, get list of commits on the upstream branch with ?exclude=<branch> to see how many commits behind it is

This works, but rapidly hits the 1k/hr rate limit on calls to the commits route, and it's horribly slow with more than a handful of repos & branches, and worse yet with multiple pages of commits as the paginated commits API does not provide a full result set count. I understand the rate limits, and for the performance on both ends I would much rather a cleaner way of doing this, but I can't find any other option anywhere in the SDK docs. Have I missed something?

5 answers

1 vote
Arthur V.
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
March 6, 2018

+1

Same question, same problem.

Why this feature available on Web UI is not available into API.

Saif June 20, 2019

Absolutely a must feature.

We are highly interested in this. 

Any possible availability in near upcoming releases?

0 votes
Daniele Gaffuri
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
February 2, 2024

Debugging front end I've found an internal API that is callable with OAuth: 

https://bitbucket.org/api/internal/repositories/<repo>/branch-list/?q=name != "master" AND (ahead = 0 OR ahead = null)

 

0 votes
elicier_molina_contractor
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
January 14, 2021

One more here

0 votes
derbenoo
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
November 15, 2019

+1

0 votes
manu
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
October 15, 2019

+1 here. 

Suggest an answer

Log in or Sign up to answer
TAGS
atlassian, ace, atlassian community event, donation, girls who code, women in tech, malala fund, plan international, kudos, community badge, badge, atlassian badge, International Women’s month, International Women’s Day, women's month, women's day

10 for Change at Atlassian Community Events

Show up and give back by attending an Atlassian Community Event: we’ll donate $10 for every event attendee in March!

Join an Atlassian Community Event!
AUG Leaders

Upcoming Bitbucket Events