Group-level protected branches - All protected branches
requested to merge gitlab-jh/jh-team/gitlab:feature/group-level-protected-branch-backend-3 into master
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)
- Add
all_protected_branches
andgroup_protected_branches
inProject
model. - Find and update the usage of
project.protected_branches
withproject.all_protected_branches
at the required places in the codebase. This should be behind a feature flag.
How to set up and validate locally
-
Enable the feature flag
Feature.enable(:group_protected_branches)
-
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.
-
I have evaluated the MR acceptance checklist for this MR.
/cc EM @daveliu
Edited by Song Huang