Gitlab API does not manage default_branch_protection = 3 value
Summary
Only values 0 to 2 are described into https://docs.gitlab.com/ce/api/settings.html for parameter default_branch_protection. At least since Gitlab 11.0.5 (my current version) the value 3 exists and means "Protected against pushes: Developers cannot push new commits, but are allowed to accept merge requests to the branch. Mainteners can push to the branch." The documentation and the API is not up-to-date to set automatically this parameter to 3
Steps to reproduce
- Go into your project into "Admin Area > Settings > General > Visibility and access controls"
- Set default branch protection to "Protected against pushes: Developers cannot push new commits, but are allowed to accept merge requests to the branch. Mainteners can push to the branch."
- By using a command like curl --header "PRIVATE-TOKEN: " https:///api/v4/application/settings` see that default_branch_protection value is 3
- Change the value into the GUI or let it like that
- Run the following command to set the value to 3 curl --request PUT --header "PRIVATE-TOKEN: " https:///api/v4/application/settings?default_branch_protection=3. An error "error":"default_branch_protection does not have a valid value" is raised
- Do the same with value 0, 1 or 2 it will work
Example Project
What is the current bug behavior?
As explained above the API does not allow to change default_branch_protection value to 3
What is the expected correct behavior?
- The documentation https://docs.gitlab.com/ce/api/settings.html should mention this value 3 since it is possible to retrieve it with a GET
- The API should allow to set the value to 3 since it is possible with the GUI
Relevant logs and/or screenshots
$ curl --request PUT --header "PRIVATE-TOKEN: <YourToken>" -k https://<yourgitlab>/api/v4/application/settings?default_branch_protection=3
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 65 100 65 0 0 296 0 --:--:-- --:--:-- --:--:-- 296{"error":"default_branch_protection does not have a valid value"}
Output of checks
This bug happens on a Gitlab 11.5.0 under docker on my platform for the API part. For the documentation part on GitLab.com
Results of GitLab environment info
System information
System:
Current User: git
Using RVM: no
Ruby Version: 2.4.5p335
Gem Version: 2.7.6
Bundler Version:1.16.6
Rake Version: 12.3.1
Redis Version: 3.2.12
Git Version: 2.18.1
Sidekiq Version:5.2.1
Go Version: unknown
GitLab information
Version: 11.5.0
Revision: b7b1e8e
Directory: /opt/gitlab/embedded/service/gitlab-rails
DB Adapter: postgresql
URL: https://<myhost>
HTTP Clone URL: https://<myhost>/some-group/some-project.git
SSH Clone URL: ssh://git@<myhost>/some-group/some-project.git
Using LDAP: no
Using Omniauth: yes
Omniauth Providers:
GitLab Shell
Version: 8.4.1
Repository storage paths:
- default: /var/opt/gitlab/git-data/repositories
Hooks: /opt/gitlab/embedded/service/gitlab-shell/hooks
Git: /opt/gitlab/embedded/bin/git
Results of GitLab application Check
Checking GitLab Shell ...
GitLab Shell version >= 8.4.1 ? ... OK (8.4.1)
hooks directories in repos are links: ...
4/4 ... ok
4/5 ... repository is empty
4/15 ... ok
4/16 ... ok
4/18 ... ok
4/19 ... ok
4/20 ... ok
4/22 ... ok
Running /opt/gitlab/embedded/service/gitlab-shell/bin/check
Check GitLab API access: OK
Redis available via internal API: OK
Access to /var/opt/gitlab/.ssh/authorized_keys: OK
gitlab-shell self-check successful
Checking GitLab Shell ... Finished
Checking Gitaly ...
default ... OK
Checking Gitaly ... Finished
Checking Sidekiq ...
Running? ... yes
Number of Sidekiq processes ... 1
Checking Sidekiq ... Finished
Reply by email is disabled in config/gitlab.yml
Checking LDAP ...
LDAP is disabled in config/gitlab.yml
Checking LDAP ... Finished
Checking GitLab ...
Git configured correctly? ... yes
Database config exists? ... yes
All migrations up? ... yes
Database contains orphaned GroupMembers? ... no
GitLab config exists? ... yes
GitLab config up to date? ... yes
Log directory writable? ... yes
Tmp directory writable? ... yes
Uploads directory exists? ... yes
Uploads directory has correct permissions? ... yes
Uploads directory tmp has correct permissions? ... yes
Init script exists? ... skipped (omnibus-gitlab has no init script)
Init script up-to-date? ... skipped (omnibus-gitlab has no init script)
Projects have namespace: ...
4/4 ... yes
4/5 ... yes
4/15 ... yes
4/16 ... yes
4/18 ... yes
4/19 ... yes
4/20 ... yes
4/22 ... yes
Redis version >= 2.8.0? ... yes
Ruby version >= 2.3.5 ? ... yes (2.4.5)
Git version >= 2.9.5 ? ... yes (2.18.1)
Git user has default SSH configuration? ... yes
Active users: ... 9
Checking GitLab ... Finished