Fix bug that caused a merge to show an error message
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:
-
When a merge request is created,
MergeRequests::CreateService
syncs some project approval rules (e.g. report types) to the list of merge request approvals. -
If only the
any_approver
rule is present,ApprovalRules::FinalizeService
will attempt to create a new merge request approval rule sincemerge_request.approval_rules.regular.exists?
isfalse
.
To fix this, we don't copy over the merge request rule if one by the same name already exists.
Closes #32477 (closed)