benji_r
benji_r

Reputation: 555

How to fetch number of commits at Bitbucket using its API

Is there a way to fetch the number of commits through the Bitbucket API and use it in a program? I don't want to show any message or anything just the number of the commits by all the programmers in a section.

I've looked at the API documentation but still wasn't able to do it.

Upvotes: 2

Views: 3973

Answers (1)

Rudy Matela
Rudy Matela

Reputation: 6460

You can use the following url to query the number of changesets:

https://bitbucket.org/api/1.0/repositories/{account}/{repo}/changesets?limit=0

You have to change {account} and {repo} for the account an repository you want to know. It will return a JSON with a count field denoting the number of commits in that repository. Remember to set the limit=0 parameter (which provides general info without listing the commits themselves).

Example

To know the number of commits in the atlassian-plugins repo from atlassian using curl command line tool:

$ curl "https://bitbucket.org/api/1.0/repositories/atlassian/atlassian-plugins/changesets?limit=0"
{"count": 4449, "start": null, "limit": 0, "changesets": []}

Check the first field, count, it shows that the repository has 1234 commits.

Upvotes: 1

Related Questions