Find list of changed files within a Pull Request
Platform Notice: Cloud Only - This article only applies to Atlassian products on the cloud platform.
Summary
In a given scenario, a user may want to know the size of the changed files within a Pull Request
This information can be used to decide if they want to run a pipeline to that Pull Request.
Environment
Bitbucket Cloud.
Solution
It is possible to retrieve the list of changed files from the API with the following steps:
Make an API call to GET a Pull Request endpoint. Example:
1 2 3 4
curl --request GET \ --url 'https://api.bitbucket.org/2.0/repositories/{workspace}/{repo_slug}/pullrequests/{pull_request_id}' \ --header 'Authorization: Bearer <access_token>' \ --header 'Accept: application/json'
On the payload, you will find the link for the diffstat (links.diffstat.href)
Perform a GET request, using Curl for example, to the diffstat URL retrieved and retrieve the size with the "wc -c" command. Example:
1
curl -u <Bitbucket-Username>:<App-Password> "https://api.bitbucket.org/2.0/repositories/{workspace}/{repo_slug}/diffstat/{workspace}/{repo_slug}:{diffstat_hash}?from_pullrequest_id={pull_request_id}&topic=true" | wc -c
Updated on March 17, 2025
Was this helpful?
Still need help?
The Atlassian Community is here for you.