How to Get User Commits from Bitbucket Repository
Retrieving commits made by a contributor to a particular repository with built-in Bitbucket functionality can be challenging. This article will show how to get user commits from Bitbucket Data Center over a specific period using the app from Atlassian Marketplace called Awesome Graphs for Bitbucket.
Awesome Graphs is the app that enhances the functionality of Bitbucket and allows users to track commit and pull request history in a series of graphs and reports as well as export the needed data. With it, you can retrieve commits and PRs details at various levels – global, project, repository, and user. In this article, we’ll focus on how to get commit data for a particular user.
Get user commits from Bitbucket
There are two primary ways to retrieve user’s commits from Bitbucket Data Center using Awesome Graphs:
- export from the Bitbucket UI into a CSV file
- export via the REST API in either CSV or JSON format
Below, we’ll guide you through getting commits using the REST API resources. In our documentation, you can learn how to export user commits to CSV from Bitbucket UI in just a few clicks.
Export all user commits using the REST API
REST API request to get commits in CSV format
Here is an example of a request that returns a list of commits of a particular user, including commits made by the user’s aliases to a CSV file:
curl -X GET -u username:password
"https://%bitbucket-host%/rest/awesome-graphs-api/latest/users/{userSlug}/commits/export/csv"
This command will export commit data for the last 30 days by default. However, you can modify the time using the sinceDate and untilDate parameters and export data for up to 366 days.
After running the request, you’ll get a CSV file with the list of commits a particular user worked on and their details, including date, project, repository name, and number of lines of code added and deleted.
REST API request to get commits in JSON format
If you need commit data in JSON format, use the following command structure:
curl -X GET -u username:password
"https://%bitbucket-host%/rest/awesome-graphs-api/latest/users/{userSlug}/commits"
This request will return detailed information about each commit, including the commit ID, author, timestamp, and lines of code added or deleted. Here is an example of data you’ll receive when exporting user commits in JSON format:
{
"values"
: [
{
"authorTimestamp"
:
"2024-09-20T04:49:44-05:00"
,
"user"
: {
"emailAddress"
:
"mxschmitt@github.com"
,
"displayName"
:
"Max Schmitt"
,
"name"
:
"mxschmitt"
},
"author"
: {
"displayName"
:
"Max Schmitt"
,
"emailAddress"
:
"max@schmitt.mx"
},
"linesOfCode"
: {
"added"
:
22
,
"deleted"
:
1
},
"parents"
: [
{
"id"
:
"ace8cb2427d77dc51377"
}
],
"repository"
: {
"slug"
:
"playwright"
,
"name"
:
"playwright"
,
"project"
: {
"key"
:
"MICROSOFT"
,
"name"
:
"Microsoft"
,
"type"
:
"NORMAL"
}
},
"id"
:
"9117562377b8122b4db16f599bda54d809679021"
},
{
"authorTimestamp"
:
"2024-09-20T02:36:03-05:00"
,
"user"
: {
"emailAddress"
:
"mxschmitt@github.com"
,
"displayName"
:
"Max Schmitt"
,
"name"
:
"mxschmitt"
},
"author"
: {
"displayName"
:
"Max Schmitt"
,
"emailAddress"
:
"max@schmitt.mx"
},
"linesOfCode"
: {
"added"
:
0
,
"deleted"
:
0
},
"parents"
: [
{
"id"
:
"a6e49854248c57c5c66a"
},
{
"id"
:
"935aa6b020f9660aed37"
}
],
"repository"
: {
"slug"
:
"playwright"
,
"name"
:
"playwright"
,
"project"
: {
"key"
:
"MICROSOFT"
,
"name"
:
"Microsoft"
,
"type"
:
"NORMAL"
}
},
"id"
:
"7feb943c80e25b358c1ec690e6f32cf6701f21b8"
},
],
"isLastPage"
:
false
,
"nextPageStart"
:
2
,
"start"
:
0
,
"size"
:
2
,
"limit"
:
2
}
As in the previous example, you can specify the timeframe for the data you need to retrieve by adding the sinceDate and untilDate parameters to the API request.
Get user commits from Bitbucket repository
Using the above requests to the Awesome Graphs REST API, you will get a list of all commits made by the user in all projects and repositories for a certain period. To filter the list and get commits of a particular repository, you can either:
- use a CSV export, which allows you to filter the data manually
- create a custom script to extract the data in JSON format based on your criteria
If you need help developing custom scripts or automating data exports, our experts can create custom solutions tailored to your needs. This service is available for Awesome Graphs clients with a Premium Support subscription.
Following the steps outlined in this guide, you can easily get user commits from Bitbucket Data Center and adjust the data to your specific needs. Moreover, using Awesome Graphs, you will have quick access to all user activities in Bitbucket UI.
Try Awesome Graphs for Bitbucket for free to see how your team can benefit from using this solution.