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

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,641,229
Community Members
 
Community Events
196
Community Groups

Is this Branch Restriction - Merge Settings API available?

Edited

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

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.
Sep 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)

"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.
Nov 01, 2022 • edited

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)

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.
Nov 01, 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