Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Is this Branch Restriction - Merge Settings API available?

Karthikraj September 27, 2022

Hi Team,

 

I used branch restriction API and created the branch restrictions and then for merge settings I couldn't find the API. Is this available ? 

2 answers

0 votes
Karthikraj October 12, 2022

Hi @Ben ,

 

Thanks for the reply.

my requirement is,  in merge settings how to define the Merge checks & Merge Conditions through API?

 

Thanks & Regards.

Karthikraj M

0 votes
Ben
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
September 29, 2022

Hey Karthikraj!

Welcome to the Bitbucket Cloud community! :)

The merge restriction option is included within the same /2.0/repositories API endpoint that you have been using and can be passed as a JSON argument.

For example, if I was to restrict merges for the master branch to only the admin user group - the JSON argument would look like this:

{
"branch_match_kind":"glob",
"pattern":"master",
"kind":"restrict_merges",
"groups":[
{
"slug":"admin"
}
]
}

Hope this helps.

Cheers!

- Ben (Bitbucket Cloud Support)

Karthikraj October 31, 2022
"kind": "restrict_merges",
"branch_match_kind": "glob",
"pattern":"develop",
"groups": [
{
"slug": "administrators",
"full_slug": "fii:administrators",
"name": "Administrators",
"default_permission": "admin",
"account_privilege": "admin"
}
]
requests.exceptions.HTTPError: 400 Client Error: Bad Request for url: https://api.bitbucket.org/2.0/repositories/*****/*****/branch-restrictions
Ben
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
November 1, 2022

Hey Karthikraj,

Just letting you know firstly that I have edited your comment to censor out your workspaceID/reposlug as this is a public forum.

May I ask if you are using AppPassword to authenticate? If you are not already doing so, please follow our guide below for configuring an AppPassword:
https://support.atlassian.com/bitbucket-cloud/docs/app-passwords/

I have been able to successfully execute the cURL command with JSON that you have listed above on my own repository, please ensure the format is correct and then attempt to execute:

curl -X POST \
  --url 'https://api.bitbucket.org/2.0/repositories/{workspaceID}/{reposlug}/branch-restrictions?=' \
  --user {username}:{AppPassword} \
  --header 'Content-Type: application/json' \
  --data '{
"kind": "restrict_merges",
"branch_match_kind": "glob",
"pattern":"develop",
   "groups":[
      {
        "slug":"administrators",
"full_slug": "{workspaceID}:administrators",
        "name": "Administrators",
"default_permission": "admin",
        "account_privilege": "admin"
      }
   ]
}
'

 NOTE: You will need to replace {workspaceID}, {reposlug}, {username}, {AppPassword} with actual values without the curly braces

Please try this and let me know how it goes.

Cheers!

- Ben (Bitbucket Cloud Support)

Karthikraj November 1, 2022

Hello @Ben ,

 

for cURL its working for me too. But, I try to use it in python its shows bad request error. How to define the "groups" in python code ?

the same JSON format should work right?  

 

requests.exceptions.HTTPError: 400 Client Error: Bad Request for url: https://api.bitbucket.org/2.0/repositories/******/******/branch-restrictions

 

Thanks & Regards,

Karthikraj M

Ben
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
November 1, 2022

Hi Karthikraj,

To be honest - I am not very well versed in Python to give you a definitive answer as to how to format the JSON correctly.

I have found the following article on StackOverflow that addresses the 400 HTTP response error by using the json parameter in requests.post for json data that may be useful for you:
https://stackoverflow.com/questions/45206380/converting-curl-to-python-requests-error

Cheers!

- Ben (Bitbucket Cloud Support)

Suggest an answer

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

Atlassian Community Events