Situation: For a repo hosted on Bitbucket server, I have a webhook setup to send a request to an external server whenever a pull request is opened. The server then uses the Bitbucket Server API to get the diff of all files associated with the pr. This works just fine because the server account has read access to the repo with the webhook setup. What I would like to do next is get the raw files associated with the pull request.
Issue: In the instance where another user forks this repo, makes changes, and submits the pr, my server does not have read access to this users fork of the repo, and therefore to the files in their modified state.
I've looked through the Bitbucket Server documentation, but can't find any way to get the raw files other than to just read from the users repo. This works fine when the pr is from some branch in the main repo to master in the same repo, since the read permission issue does not come into play.
One possible solution I think is to use the diff, along with the files presently in the main repo to recreate the modified state of the files, but I would like to avoid this.
Any way to do this without having every user submitting a pr to give read access to the server account?
Thanks
This isn't exactly documented anywhere but as soon as a Pull Request is opened, BitBucket creates several pull-request related references. You are probably interested in the following two.
So, you could checkout either of these (depending on which you want) which will get you all the files (modified and others) using refspec.
i.e.
+refs/pull-requests/[PR_ID]/*:refs/remotes/origin/pull-requests/[PR_ID]/*
Then, you could get the paths of modified files using the PR Changes REST API and retrieve the files using these paths from the disk (where-ever you checked out).
However, it's worth noting that BitBucket team warns that these implementations are for internal use only and is subject to change without any warning. But the implementation hasn't changed in over 6 years.