Skip to content

Fix approval policy to include group level protected branch

What does this MR do and why?

This MR fixes a bug with MR approval rules when allow_protected_branches_for_group & group_protected_branches feature flag are enabled and when a project does not have a branch that is specified in group level's protected branches.

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.

How to set up and validate locally

  1. Create a group and enabled allow_protected_branches_for_group & group_protected_branches FFs to the group
  2. Create a group level protected branch (feature) from Group -> Settings -> Repository -> Protected Branches
  3. Add the following policy below to that group (Secure -> Policies -> New Policy -> Merge request approval policy)
    ---
    scan_result_policy:
    - name: Policy test
      description: ''
      enabled: true
      actions:
      - type: require_approval
        approvals_required: 1
        role_approvers:
        - maintainer
        - owner
      rules:
      - type: any_merge_request
        commits: any
        branches:
        - feature
      approval_settings:
        block_branch_modification: true
        prevent_pushing_and_force_pushing: true
        prevent_approval_by_author: true
        prevent_approval_by_commit_author: true
        remove_approvals_with_new_commit: true
        require_password_to_approve: false
      policy_scope:
        compliance_frameworks: []
  4. Create a project within the group
  5. Create 2 more non-protected branches. (Let's call them new-branch-1 and new-branch-2)
  6. Make some changes on new-branch-2. For example, adding a new line in a README file.
  7. Create an a MR with new-branch-2 as the source branch, and new-branch-1 as the target branch.
  8. Observe that approval is not required for the MR

Addresses #456055

Edited by Sashi Kumar Kumaresan

Merge request reports