Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Trying to (in Perl) retrieve the file list from a pull request in Bitbucket

Jim Henk November 8, 2018

Have figured out how to GET the specific pull request page into json, and then into a hash, and the link for {'links'}{'diff'}{'href'} is a URL which I then tried to GET.  Unfortunately, I believe the bitbucket backend generates a unique page off of that, and then re-directs to it.  A nightmare if you need the content of that newly minted page with a unique id in the URL, impossible to anticipate.  Sigh.  If I can get that, I can parse to my heart's content, but I have to get that page in the first place.  Help?

 

2 answers

0 votes
Jim Henk December 4, 2018

After a long fruitless search, I finally found that curl has a -L parameter which will follow redirects.  Noticed that no one else had a solution for this either.  (Bitbucket - there is a need for this to be an API call...)

 

So this will give you the diff page:

my @results = `curl -L -D- -X GET -H "Authorization: Basic <your credentials here>" -H "Content-Type: application/json"  https://bitbucket.org/!api/2.0/repositories/<repo>/pullrequests/<pull request number>/diff`;  # backticks used here to run as a shell command

The @results array will need to be parsed six ways from Sunday from here, but that's half the fun.

0 votes
Jim Henk November 8, 2018

Or is there just a plain old better way to retrieve the file list from the pull request in Perl?

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events