How to list files from commit

soin_fcastro December 28, 2015

Really a need to list files between two date.  So, im trying to get a pull requests, get commits from them and now i want to get the files (with revisions and timestamps).

Im using API CLOUD. 

Thanks!

3 answers

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

2 votes
Answer accepted
evzijst
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
December 28, 2015

There is currently no real programmatic way to get to the list of modified files in a pull request. That is, while the 1.0 API has a diffstat API that gives you the affected file names, as well as the number of lines added/removed, 2.0 does not. Furthermore, 1.0 does not understand pull request diffs; only individual commits.

Also, the diff you see in a pull requests is really the diff of the merge commit you would get if you accepted the pr. This is not always the same as any of the commits on the source branch (see a recent explanation of the difference).

So that means that to accurately compute the list of path names affected by a pr (identical to what the UI shows you), you'd need to clone both branches, merge the source into the destination branch and then compute the diff of that merge commit against its first parent (the original head of the destination branch).

Now luckily all is not lost.

The pull request API provides access to the aforementioned raw diff: https://confluence.atlassian.com/display/BITBUCKET/pullrequests+Resource#pullrequestsResource-getDiffGETthediffforapullrequest

And so a somewhat clunky (but reliable!) way to get to the information you need is to hit that diff URL and grep the lines that start with: diff --git a/...

P.S.
This won't give you information about which commit (if the source branch has multiple) introduced changes to which file. After all, the changes to a file may come from multiple commits by multiple authors.

soin_fcastro December 29, 2015

Hi Erik, im using cloud api version, and when i request it returned "forbidden", i believed about permissions but not. i think that is server and cloud limitations. Request: https://api.bitbucket.org/2.0/repositories/{repo}/{slug}/pullrequests/1/diff?access_token={valid access token} response:HTTP/1.1 403 FORBIDDEN Server: nginx/1.6.2 Vary: Authorization, Cookie Content-Type: text/plain Strict-Transport-Security: max-age=31536000 Date: Tue, 29 Dec 2015 15:41:33 GMT X-Served-By: app22 X-Static-Version: bc3111412fb8 ETag: "722969577a96ca3953e84e3d949dee81" X-Render-Time: 0.00816607475281 X-Accepted-OAuth-Scopes: repository Connection: close X-Version: bc3111412fb8 X-Request-Count: 152 X-Frame-Options: SAMEORIGIN Content-Length: 9

evzijst
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
December 29, 2015

Does your token have the "repository" scope? Are you sure the token is not expired (they expire after an hour)? If you can't work it out, then it's best to contact us at support@bitbucket.org and we can help you debug your OAuth issues.

soin_fcastro December 29, 2015

hi, i checked them, and the message is same. Question, i need write permissions for make a diff request?

evzijst
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
December 29, 2015

No, you do not. Actually, since this is pull request resource, you also need the "pullrequest" scope. Did you check for that?

evzijst
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
December 29, 2015

No, the restbowser is not the Server version. Anyway, let's move this to support. Answers is for product questions and less suited to interactive debugging. Can you email either support@bitbucket.org or me (erik@atlassian.com) with full traces of your request?

soin_fcastro December 29, 2015

ok, thanks

0 votes
soin_fcastro January 4, 2016

my error was "redirect" option enabled. I corrected that and all requests was ok 302! thanks Erik!

0 votes
soin_fcastro December 29, 2015

Yes my friend, in my case, https://api.bitbucket.org/2.0/repositories/{repo}/{slug}/pullrequests/1/diff?access_token={valid access token}, 1 = is the pullrequest id. By example, im using http://restbrowser.bitbucket.org/ with Auth in this: https://api.bitbucket.org/2.0/repositories/soinrepos/erp-7.0/pullrequests/1/diff?access_token=CIDOqo8TjFpT6V5-IEUM9uscUqESvn9gcu9T1bxgY3UOGtkDldUgoa3wmgZ1YYFmRUd0HaWnSdSSvB7K3w== and return HTTP/1.1 302 FOUND. But, from my cloud api doesnt work, im thinking that http://restbrowser.bitbucket.org/ is server version

TAGS
AUG Leaders

Atlassian Community Events