Skip to content

Use new json column for default branch protection

What does this MR do and why?

Use new json column for default branch protection

This commit adds the functionality to start using new json column for creating default branch protection instead of using the old integer column

EE: true

MR acceptance checklist

Please evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.

Screenshots or screen recordings

Screenshots are required for UI changes, and strongly recommended for all other merge requests.

Before After

How to set up and validate locally

Use API put groups/:id to update default branch protection settings, when the feature flag is disabled use the below json body:

{
"default_branch_protection": 2
}

When the feature flag is enabled use the below json body:

{
"default_branch_protection_defaults": {
        "allowed_to_push": [
            {
                "access_level": 40
            }
        ],
        "allow_force_push": false,
        "allowed_to_merge": [
            {
                "access_level": 40
            }
        ]
    }
}

For the json values for each setting, you can refer to class https://gitlab.com/gitlab-org/gitlab/-/blob/master/lib/gitlab/access/branch_protection.rb?ref_type=heads

and call Gitlab::Access::BranchProtection.new(level).to_hash this will give you converted values from integer to json.

  1. Enable feature flag: default_branch_protection_defaults
  2. Change default branch protection setting using group put API
  3. Create a project and check we have correct protected branches.
setting feature flag disabled feature flag enabled
Protection None Screenshot_2024-02-19_at_6.42.52_PM Screenshot_2024-02-19_at_6.48.12_PM
Protection Partial Screenshot 2024-02-19 at 7.04.26 PM.png Screenshot 2024-02-19 at 6.53.39 PM.png
Protected Fully Screenshot 2024-02-19 at 7.05.42 PM.png Screenshot_2024-02-19_at_6.55.43_PM
Protected Against Developer Pushes Screenshot 2024-02-19 at 7.07.05 PM.png Screenshot_2024-02-19_at_6.57.56_PM
Developer can initial push Screenshot 2024-02-19 at 7.08.29 PM.png Screenshot_2024-02-19_at_7.01.49_PM

Related to #408152 (closed)

Edited by Harsimar Sandhu

Merge request reports