How can I efficiently get the number of commits a branch is ahead/behind using the REST API? 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?

0 answers

Suggest an answer

Log in or Join to answer
Community showcase
Piotr Plewa
Published Dec 27, 2017 in Bitbucket

Recipe: Deploying AWS Lambda functions with Bitbucket Pipelines

Bitbucket Pipelines helps me manage and automate a number of serverless deployments to AWS Lambda and this is how I do it. I'm building Node.js Lambda functions using node-lambda&nbsp...

635 views 0 4
Read article

Atlassian User Groups

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

Find a group

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

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you
Atlassian Team Tour

Join us on the Team Tour

We're bringing product updates and pro tips on teamwork to ten cities around the world.

Save your spot