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

How to get commit code that belongs to a jira issue by Development Rest API

Bashayer Alsalman May 22, 2023

I want to get the difference between the code when pulling the commits via development API,

 

I got the list of issues and then the list of commits that are related to the Jira Issue, but I could not get the exact source code.

1 answer

0 votes
Patrik S
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
May 23, 2023

Hello @Bashayer Alsalman and welcome to the Community!

As you mentioned you were already able to get the list of issues and their related commits, if you want to compare the diff between commits, the Compare two commits endpoint can be used: 

https://api.bitbucket.org/2.0/repositories/<workspace>/<repository>/diff/<spec>

Where the spec parameter can be a commit id, a branch name, or a tag.

Following is an example request to get the diff between two commits : 

curl -X GET -u USERNAME:APP_PASSWORD https://api.bitbucket.org/2.0/repositories/<workspace>/<repository>/diff/aa35f95..259de05

This should return the diff between the source commit and the merge base of the source commit and the destination commit.

However, if you want to get the content of files/directories within the repository, then the Get file of directory contents endpoint might be useful. Below is an example request listing all the files and directories up to max_depth in commit 259de05

https://api.bitbucket.org/2.0/repositories/<workspace>/<repository>/src/259de05/?max_depth=10

The max_depth will control the number of nested directories that will be returned. The object returned from this API will just contain the list of the files/directories. If you would like to get the actual raw content of a file, you will need to follow the links.self.href of each file entry returned in the JSON.

Hope that helps! Let me know in case you have any questions.

Thank you, @Bashayer Alsalman !
Patrik S

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events