Introduce concept of a project approval rule targeting "All protected branches"
What does this MR do and why?
Adds a new concept to project approval rules that it can be targeted to "All protected branches". This is achieved by adding a new flag to project approval rules which, when set to true
overrides the associated list of protected_branches
to be all protected branches for the associated project.
The APIs should also return a dynamic list of protected branches when this option is enabled.
-
New feature flag -
Adds new database column project_approval_rules.applies_to_all_protected_branches
-
New logic in ApprovalProjectRule
that handles the use of this new column. -
Addition to REST APIs (Create) -
Addition to REST APIs (Update) -
Specs for REST API changes -
GraphQL changes & specs
Database Review
Migrate
main: == 20220531140515 AddAppliesToAllProtectedBranchesToApprovalProjectRule: migrating
main: -- add_column(:approval_project_rules, :applies_to_all_protected_branches, :boolean, {:default=>false, :null=>false})
main: -> 0.0107s
main: == 20220531140515 AddAppliesToAllProtectedBranchesToApprovalProjectRule: migrated (0.0122s)
Rollback
main: == 20220531140515 AddAppliesToAllProtectedBranchesToApprovalProjectRule: reverting
main: -- remove_column(:approval_project_rules, :applies_to_all_protected_branches, :boolean, {:default=>false, :null=>false})
main: -> 0.0130s
main: == 20220531140515 AddAppliesToAllProtectedBranchesToApprovalProjectRule: reverted (0.0184s)
Screenshots or screen recordings
These are strongly recommended to assist reviewers and reduce the time to merge your change.
How to set up and validate locally
- Enable the feature flag:
Feature.enable(:project_approval_rule_all_protected_branches)
- In a project, create an approval rule targeting all branches.
- Since this is only the backend part of this feature, we'll need to use the console to apply the new "Applies to all protected branches" flag:
rule = ApprovalProjectRule.last
rule.update!(applies_to_all_protected_branches: true)
rule.reload
- Load the list of protected branches:
rule.protected_branches
Test the API
- On a project, load the approval rules:
GET /api/v4/projects/6/approval_settings
. - Check that the
applies_to_all_protected_branches
field returnstrue
and that the list ofprotected_branches
is a dynamic list of protected ranches belonging to the project. This should update automatically when a new protected branch is added to the project.
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.
Related to #335316 (closed)
Edited by Max Woolf