Update/add the merge check "Keep approvals if there is no change to the diff in the pull request" to branch restrictions via API
Platform Notice: Cloud Only - This article only applies to Atlassian products on the cloud platform.
Summary
How to change the branch restriction - "Keep approvals if there is no change to the diff in the pull request" for multiple repositories at once?
Diagnosis
Premium customers have some additional branch restrictions available to them which are mentioned in our documentation. The setting "Keep Approvals if there is no change to the diff" as the name suggests, will not discard approvals when there are new empty commits to the Pull Request or when rebasing the source branch does not change the diff. Sometimes, customers will want to enable this for all their repositories or many repositories in bulk as this is a useful branch restriction to have. Doing this on a per-repository basis can be cumbersome.
Solution
Our branch restriction API has a parameter called kind which enables different types of restrictions. The value - smart_reset_pullrequest_approvals is responsible for enabling the "Keep Approvals if there is a change to the diff" option.
Here is a sample curl command to add the setting to the master branch for a specific repository -
1
curl -i --request POST -H "Content-Type: application/json" -u username:app-password "https://api.bitbucket.org/2.0/repositories/<workspaceID>/<reposlug>/branch-restrictions" -d '{ "pattern": "master","kind": "smart_reset_pullrequest_approvals"}'
You can find more about app password from here.
This can be done in bulk programmatically to enable it for all repositories.
Was this helpful?