Add reasons to failed merge trains

What does this MR do and why?

When a merge request is automatically removed from a merge train because a mergeability check fails, the note we leave behind only says Merge request is not mergeable — with no hint about what actually blocked it.

This MR makes that message explain the reason. Each mergeability check now carries a human-readable failure_reason, and when an MR is dropped from a train we surface the primary blocking check, e.g.:

Merge request is not mergeable. Reason: The merge request must not be a draft.

Implementation notes

  • Every Mergeability::Check...Service gains a set_failure_reason describing, in plain language, what needs to be true for it to pass.
  • A small value object, MergeRequests::Mergeability::DetailedFailureMessage, builds the message. It reads the primary blocking check straight from the fail-fast mergeability result (execute_merge_checksunsuccessful_check), so it stays cheap and never triggers the expensive "run every check" path.
  • The detailed message is used only in the merge-train path (FromTrainRef), matching the scope of the issue. The regular merge path is unchanged.
  • Behind the merge_request_detailed_failure_reasons feature flag (gitlab_com_derisk, default off).

How to set up and validate locally

Add a merge request to a merge train where you know it'll fail. The reason should appear in the "removed from the merge train" system note. For example:

  1. Enable the flag: Feature.enable(:merge_request_detailed_failure_reasons).
  2. Add a rule that blocks draft MRs from auto-merging.
  3. Set the MR to "not draft", add it to the merge train, then set it back to draft.
  4. Observe the detailed reason in the notes below the merge request.

MR acceptance checklist

Evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.

Issue https://gitlab.com/gitlab-org/gitlab/-/work_items/594774

Edited by Daniel Prause

Merge request reports

Loading