Skip to content

Allow "all protected branches" for MR approval rules in projects

What does this MR do and why?

This MR adds the ability to mark an approval rule as being applicable to all protected branches.

It also updates the all branches logic so it is easier to differentiate in the code between the all options now available. This means that we also need to check status checks and the policy builder too to make sure that this logic change doesn't break their functionality.

This now means that an approval rule can be set to be applied to all protected branches and this rule will then propagate to any MR which targets one of those branches. The backend handles which branches this covers.

Screenshots or screen recordings

MR approval rules

Screen_Recording_2022-07-19_at_14.42.05

Status checks branch selection (validating the all branches change)

Screen_Recording_2022-07-19_at_14.55.22

Policy builder branch selection (validating the all branches change)

Screen_Recording_2022-07-19_at_14.51.27

How to set up and validate locally

MR approval rules

  1. Enable the feature flag :project_approval_rule_all_protected_branches : echo "Feature.enable(:project_approval_rule_all_protected_branches)" | rails c.
  2. Visit a projects settings page and open the Merge request approvals section e.g. http://gdk.test:3000/gitlab-org/gitlab-test/edit#js-merge-request-approval-settings.
  3. Create or edit an approval rule and test that you can select all branches, all protected branches and a specific branch by selection or search.
  4. Test that setting all branches or all protected branches and saving the approval rule shows the correct value on the rules list.
  5. Create a new MR and test that the approval rule with all branches or all protected branches is picked up.
  6. Create a new MR targeting a non-protected branch and check that the all protected branches rule is not picked up.

Status checks branch selection

  1. Visit a projects settings page and open the Merge requests > Status checks section e.g. http://gdk.test:3000/gitlab-org/gitlab-test/edit#js-merge-request-settings
  2. Create or edit a status check and test that you can select all branches and a specific branch by selection or search.
  3. Confirm all protected branches is not shown.
  4. Test saving a status check, all branches is shown on the status checks list.

Policy builder branch selection

  1. Visit a projects security policies page and create or edit a new scan result policy e.g. http://gdk.test:3000/gitlab-org/gitlab-test/-/security/policies/new?type=scan_result_policy
  2. Test that you can select all branches or a specific branch via selection or search and it sets the right-hand side YAML correctly.

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 #360930 (closed)

Edited by Robert Hunt

Merge request reports