Skip to content

Fix bug that caused a merge to show an error message

Stan Hu requested to merge sh-fix-any-approver-handling into master

When a project approval rule is created that requires N approvers in the project (also known as an any_approver rule), MergeService would always fail with a "Name has already been taken" validation error.

This causes MergeWorker to run again and show different error messages to the user. If squashing were enabled, users would see, "Merge failed: Failed to squash. Should be done manually.. Please try again." Otherwise, users would see, "Merge failed: Merge request is not mergeable". In both cases, the merge was actually successful.

This error occurred because:

  1. When a merge request is created, MergeRequests::CreateService syncs some project approval rules (e.g. report types) to the list of merge request approvals.

  2. If only the any_approver rule is present, ApprovalRules::FinalizeService will attempt to create a new merge request approval rule since merge_request.approval_rules.regular.exists? is false.

To fix this, we don't copy over the merge request rule if one by the same name already exists.

Closes #32477 (closed)

Edited by Stan Hu

Merge request reports

Loading