Branch restriction - custom settings changes via API

Elena Dzhordzhilova September 21, 2023

Dear Bitbucket Community, 

 

I have a question regarding branch restrictions - I created new branch restriction via the API. The group which I white listed for push has also rights to delete or rewrite the branch. If the restriction is created via the interface, those settings are not marked by default and I would want to disable them via the API. I looked for flags, related with the custom settings, where they appear when are in use, but I did not find anything. This is the payload which I use with POST request to create the branch restriction:

 

{
"type": "branch",
"branch_match_kind": "glob",

"users": [],
"groups": [
{
"slug": "my-team",
"type": "group"

}
],
"kind": "push",
"pattern": "elena-branch",
}
)


Even with default_permission and account_privilege flag, the permissions for delete and rewrite branch histrory are still active:

{
"branch_match_kind": "glob",
"groups": [{
"default_permission": "read",
"account_privilege": "read",
"name": "my-team",
"slug": "my-team",
"type": "group"
}],
"kind": "push",
"pattern": "elena-branch"
}

 

1 answer

1 accepted

0 votes
Answer accepted
Mark C
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
September 24, 2023

Hi @Elena Dzhordzhilova,

Thank you for reaching out to the community.

I understand that you'd like to uncheck the two branch restriction settings below via API:

  • "Allow rewriting branch history"
  • "Allow deleting this branch"

If that's correct, you can uncheck those settings by running two POST commands specifically changing the parameter "kind":

To uncheck "Allow rewriting branch history", you can use the CURL command below:

curl -u bb_username:app_password -X POST -k -H 'Content-Type: application/json; charset=utf-8' --data '{"kind": "force", "branch_match_kind": "glob", "pattern": "elena-branch"}' https://api.bitbucket.org/2.0/repositories/workspace_id/repo_name/branch-restrictions

To uncheck "Allow deleting this branch", you can use the CURL command below:

curl -u bb_username:app_password -X POST -k -H 'Content-Type: application/json; charset=utf-8' --data '{"kind": "delete", "branch_match_kind": "glob", "pattern": "elena-branch"}' https://api.bitbucket.org/2.0/repositories/workspace_id/repo_name/branch-restrictions

I hope it helps and let me know how it goes.

Regards,
Mark C

Elena Dzhordzhilova September 25, 2023

Hello @Mark C !

 

Thank you a lot for the help!

Both POST commands worked as expected and the functionalities are disabled for the desired branch! 

 

Best Regards, 

Elena

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
TAGS
AUG Leaders

Atlassian Community Events