79109320

Date: 2024-10-21 09:08:40
Score: 3
Natty:
Report link

I had similar issue and figured out to make it work. Here are the steps:

  1. Retrieve Access Token

export access_token=$(curl -s -X POST -u "<client_id>:<client_secret>" \ https://bitbucket.org/site/oauth2/access_token \ -d grant_type=client_credentials -d scopes="repository" | jq --raw-output '.access_token')

Replace <client_id> and <client_secret> with your OAuth consumer credentials.

  1. Get Branch Restrictions

curl --request GET \ --url 'https://api.bitbucket.org/2.0/repositories///branch-restrictions' \ --header 'Authorization: Bearer '${access_token}'' \ --header 'Accept: application/json'

Replace and accordingly. It will print out JSON response of all available branch restrictions for the repository. Find the branch and restriction_id for which to make the next changes.

  1. Update Branch Restriction

curl --request PUT \ --url 'https://api.bitbucket.org/2.0/repositories///branch-restrictions/<restriction_id>' \ --header 'Authorization: Bearer '${access_token}'' \ --header 'Accept: application/json' \ --header 'Content-Type: application/json' \ --data '{ "type": "branchrestriction", "users": [ { "type": "user", "username": "" } ], "groups": [] }'

Replace , , <restriction_id>, and as needed. Funny thing here is that, in username, you can actually specify the workspace name, which will add your workspace "user" to the restrictions and pushback will work as intended. Please let me know if you made it work, I'm happy to assist you on this, as I know how pain it was for me to figure it out.

Reasons:
  • RegEx Blacklisted phrase (2.5): Please let me know
  • Long answer (-1):
  • No code block (0.5):
  • Low reputation (1):
Posted by: HannTheSolo