Retrieving Changed Files in Bitbucket Pull Requests

We are using a post-commit script runner to retrieve changed files. However, for pull request events, it returns an empty list while it works fine for push events.

After contacting the ScriptRunner Support Team, they informed us that this issue is due to Bitbucket. The following is a summary of the ScriptRunner Team’s response:

The use case is to retrieve a list of changed files: as you mentioned, Bitbucket doesn’t provide this information as part of the payload directly available to a post-receive hook, but ScriptRunner offers a convenience function that retrieves the information via Bitbucket’s APIs. The operation of this function is as follows:

  • Use CommitService to retrieve a list of commits involved in the pull request (getCommitsBetween).
  • For each commit, use CommitService again to retrieve the list of changes associated with that commit (getChanges).
  • Extract the filenames from each change and collect them all into a single list.

Through experimentation on the instance of Bitbucket, we discovered that while getCommitsBetween does return the correct list of commits, getChanges does not return any changes for those commits.