Overridden approval rules are removed when changing merge request target branch
Summary
To address the discussion in !22749 (comment 275470453).
#460 (closed) adds the ability to scope project-level approval rules to specific protected branches. So if the target branch of the merge request matches the scope set for an approval rule, that approval rule is applied.
In the merge request (MR) form, if I change an approval rule that is scoped to the current target branch A
(for example, approvers, name, or no. of required approvals) and save it, all is well. The changes are reflected in the MR edit form and in the MR widget. However, if I then change the target branch from A
to B
, that overridden approval rule is gone.
Steps to reproduce
- Add an approval rule scoped to branch
A
- Create a merge request targeting branch
A
- Override the approval rule created in step 1, changing its name, approvers, or no. of required approvals
- Save the form
- Edit the merge request, the overridden approval rule is visible
- Change the target branch to
B
- Save the form
- The overridden approval rule is gone
What is the current bug behavior?
Overridden approval rules (that at the project-level are scoped to a specific branch) are removed when changing merge request target branch.
What is the expected correct behavior?
Overridden approval rules should be kept when changing target branches, as that is the behavior for new approval rules that are added in the MR edit form.
Relevant logs and/or screenshots
https://www.loom.com/share/cecf016503844bbbb138cc77abc21ff5
Proposal
In the MR Create and Edit forms:
- Unlink overridden/deleted rules: If the user overrides/deletes a project approval rule, “unlink” it from the project settings. This effectively turns it into a “local” rule, as if the user had manually created it for that specific MR. Even if the project approval rule was scoped to a target branch, when overridden, it's now unscoped and applies to any target branch.
- Note: The overridden/deleted rule should still be somehow “linked” to the project rule so that the project rule does not appear again when the target branch is changed.
- Mark overridden/new rules: Add indicators next to approval rules that have been overridden or to approval rules that are new (created specifically for that MR):
- Keep overridden/new rules: When changing target branches for an MR, approval rules marked as Overridden or New are not removed/hidden. They stay visible, present, and applied to the MR until the user manually removes them.
Future iteration
- Allow resetting merge request approval rules to project defaults: #212754 (closed)