Skip to content

Group-level protected branches - All protected branches

What does this MR do and why?

Related to Create and show protected branches (#372816 - closed), this MR is followed up Group-level protected branch - policy and services (!104355 - merged)

  1. Add all_protected_branches and group_protected_branches in Project model.
  2. Find and update the usage of project.protected_branches with project.all_protected_branches at the required places in the codebase. This should be behind a feature flag.

How to set up and validate locally

  1. Enable the feature flag

    Feature.enable(:group_protected_branches)
  2. Running the these tests to validate the features:

    rspec spec/models/project_spec.rb
    rspec spec/models/protected_branch_spec.rb
    rspec spec/services/projects/protect_default_branch_service_spec.rb

Database Queries

Loading all protected branches

/*Project#all_protected_branches*/
SELECT
    "protected_branches".*
FROM ((
        SELECT
            "protected_branches".*
        FROM
            "protected_branches"
        WHERE
            "protected_branches"."project_id" = 21)
    UNION (
        SELECT
            "protected_branches".*
        FROM
            "protected_branches"
        WHERE
            "protected_branches"."namespace_id" = 73)) protected_branches

https://console.postgres.ai/gitlab/gitlab-production-tunnel-pg12/sessions/14191/commands/49778

Checking if there is a protected branch with given name

SELECT
    "protected_branches".*
FROM ((
        SELECT
            "protected_branches".*
        FROM
            "protected_branches"
        WHERE
            "protected_branches"."project_id" = 278964)
    UNION (
        SELECT
            "protected_branches".*
        FROM
            "protected_branches"
        WHERE
            "protected_branches"."namespace_id" = 9970)) protected_branches
WHERE
    "protected_branches"."name" = 'master'

https://console.postgres.ai/gitlab/gitlab-production-tunnel-pg12/sessions/14191/commands/49781

MR acceptance checklist

This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.

/cc EM @daveliu

Edited by Song Huang

Merge request reports