GitLab change permission of protected branches

Viewed 578

We recently migrated to GitLab Self Hosted (V14.3.0)

We migrated 100+ repos to Gitlab and then we realized, by default only maintainers have write access to Gitlab protected branched.

Is there a way to change the following setting in one shot for multiple repositories or we will have to manually change for every repository?

Permission

We want to change "Allowed to merge" from "Maintainers" to "Developers + Maintainers"

In the main group we have set it to the following, I was hoping that this will make it work but no luck - Group Permission

1 Answers

Well manually will be a bad approach, but the GitLab API offers a lot of functionality regarding that problem. I will not write the script, but i will outline you the APIs you can use and why you use them.

  1. Fetch a list of all projects you want to change - the Projects API

    GET /projects
    

    With this endpoint you will receive a list of all the projects within you instance, on which the user has access - be aware that this is a paginated request - so just calling it once will not be sufficient.

  2. Adapt the Protected branches - the Protected Branches API

    With the project IDs from the first part you can now query each project and change the protection. We ended up with first deleting the protection and recreating them, because it has proven to be easier.

Anyway i recommend to automate this with a script, and do it rather sooner than later. As some projects might start with custom protections, and this can make the migration harder.

Related