Bitbucket API - Merge Settings

Chris Lugar
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
May 1, 2023

Is it possible via the API to enable/disable and configure the various Merge Checks and Merge Conditions? 

In the documentation I see the ability to manage branch restrictions, but not the above features - https://developer.atlassian.com/cloud/bitbucket/rest/api-group-branch-restrictions/#api-repositories-workspace-repo-slug-branch-restrictions-post

Is there any way to manage the Merge Checks and Conditions in a batch?  I've got a large number of repositories that I need to apply some default settings for and hoping to not have to do it one by one.

Thanks

1 answer

1 accepted

1 vote
Answer accepted
Patrik S
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
May 2, 2023

Hello @Chris Lugar ,

Thank you for reaching out to Atlassian Community!

You can indeed use the branch permissions endpoint to change the configuration of merge checks and conditions as well. This can be achieved by using different values for the kind attribute in the body of the request.

Following is an example of API call to add the merge check "No unresolved pull request tasks" to a branch restriction configured to match the glob pattern development/* :

curl -X POST -H "Content-Type: application/json" -u <username>:<app_password> "https://api.bitbucket.org/2.0/repositories/<workspace>/<repoName>/branch-restrictions" -d '{ "branch_match_kind": "glob","kind": "allow_auto_merge_when_builds_pass","pattern": "development/*" }'

You can replace the kind attribute with the string that matches the desired merge check. The following options are available to be used as the value of kind : 

require_tasks_to_be_completed
allow_auto_merge_when_builds_pass
require_passing_builds_to_merge
force
require_all_dependencies_merged
require_commits_behind
restrict_merges
enforce_merge_checks
reset_pullrequest_changes_requested_on_change
require_no_changes_requested
smart_reset_pullrequest_approvals
push
require_approvals_to_merge
require_default_reviewer_approvals_to_merge
reset_pullrequest_approvals_on_change
delete

Please note that only one "kind" value can be used in each request. This means that if want to configure multiple merge checks/conditions, you'll have to make multiple requests with each merge check/condition.

Also, to delete/disable a specific merge/check condition, you will first need to get its ID from the List branch restrictions endpoint , and then provide the ID to Delete a branch restriction rule endpoint.

Hope that helps! Let me know in case you have any questions.

Thank you, @Chris Lugar !

Patrik S

Ulrich Kuhnhardt _IzymesCo_
Atlassian Partner
May 2, 2023

Thanks for sharing @Patrik S  The Bitbucket REST API link that @Chris Lugar posted only mentions 

"kind describes what will be restricted. Allowed values include: push, force, delete and restrict_merges"

Could you please investigate why the REST API document is incomplete and if that is the case update https://api.bitbucket.org/swagger.json and publish the new document.

Thanks, Ulrich

Patrik S
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
May 2, 2023

Hello @Ulrich Kuhnhardt _IzymesCo_ ,

I'm already in touch with our engineering team and we have created an internal ticket to update the documentation with all the values available for the kind attribute.

Thank you, @Ulrich Kuhnhardt _IzymesCo_ :)

Patrik S

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PERMISSIONS LEVEL
Product Admin
TAGS
AUG Leaders

Atlassian Community Events