Protected branches API - missing examples
Everyone can contribute. Help move this issue forward while earning points, leveling up and collecting rewards.
Gitlab Protected Branches API
Missing examples
Recently I had to automate protecting and unprotecting branches in one of our jobs. It was fairly easy and straightforward getting the response containing info about already protected branches, however, when protecting the branches I would appreciate at least one more example on how to set a protected branch with a bit more detail. I have some experience with basic API calls but I'm not super skilled so it took me a while until I got it working. The documentation i was checking was this. Sure enough there is an example of setting rules based on access_level
, but i had to set permissions for a group and a few other users.
There is not explicitly mentioned the format to push users, group and an access level at once.
Proposal
I propose to add one more example to the docs focused on protecting the branch and allowing an access level to push, a group and two users to merge and one user to unprotect.
curl --request POST \
--header "PRIVATE-TOKEN: <your_access_token>" \
--header "Content-Type: application/json" \
--data '{
"id": 5,
"name": "master",
"allowed_to_push": [{
"access_level": 30
}
],
"allowed_to_merge": [{
"group_id": 42
},{
"user_id": 12
},{
"user_id": 20
}
],"allowed_to_unprotect": [{
"user_id": 20
}
]}'
"https://gitlab.example.com/api/v4/projects/5/protected_branches"
PS: I have not tested this call so pls verify it.