Skip to content

Allow multiple any_merge_request rules to be created

Martin Čavoj requested to merge 418752-allow-multiple-any-mr-rules into master

What does this MR do and why?

Allow multiple merge request approval rules of report_type: any_merge_request to be created in the same way as scan_finding and license_scanning rules.

If there are multiple policies with any_merge_request type, these must correspond to multiple approval rules. Currently, only one any_merge_request approval rule is created for a merge request.

This feature behind a feature flag scan_result_any_merge_request which is disabled by default, hence no changelog entry.

While working on a test for this change, I noticed that existing test was broken in many places and not executed at all, so I fixed that too.

How to set up and validate locally

  1. In rails console enable the feature flag
    Feature.enable(:scan_result_any_merge_request)
  2. Create two policies with any_merge_request type. Sample YAML:
    type: scan_result_policy
    name: Any commits
    description: ''
    enabled: true
    rules:
      - type: any_merge_request
        branch_type: protected
        commits: any
    actions:
      - type: require_approval
        approvals_required: 1
        user_approvers_ids:
          - 1 # replace with a valid user ID
  3. Create MR in the project and verify that both rules are applied

MR acceptance checklist

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

Related to #418752 (closed)

Edited by Martin Čavoj

Merge request reports