Fix auto-merge API to merge immediately when no pipeline exists

What does this MR do and why?

When the merge API is called with auto_merge=true (or the deprecated merge_when_pipeline_succeeds=true) but no auto-merge strategy is available and no pipeline exists for the MR, the API now falls back to merging immediately if the MR is mergeable, instead of returning HTTP 405 Method Not Allowed.

Problem

Projects that skip CI pipelines for certain MRs via workflow:rules (e.g., automated cleanup MRs) cannot use merge_when_pipeline_succeeds: true because:

  1. The workflow rule suppresses the pipeline entirely
  2. No auto-merge strategy is available (nothing to wait for)
  3. diff_head_pipeline_success? returns false (no pipeline exists)
  4. The API returns 405 instead of just merging the already-mergeable MR

Solution

Extract a no_pipeline_blocking_merge? helper in the API layer that checks whether the pipeline has succeeded or no pipeline exists (and none is being created). This allows the immediate-merge fallback path in execute_merge_with_fix to handle the no-pipeline case.

This is intentionally scoped to only the no-pipeline case — a failed pipeline still returns 405, preserving existing behavior and API/UI parity.

Scenario Before After
No pipeline, CI pass not required, MR mergeable 405 Merges immediately
No pipeline, CI pass required 405 Auto-merge enabled (waits for pipeline)
No pipeline, pipeline being created 405 Auto-merge enabled (waits for pipeline)
Pipeline failed, CI pass not required 405 405 (preserved)
Pipeline succeeded, MR mergeable Merges Merges (no change)
Pipeline running Auto-merge enabled Auto-merge enabled (no change)

MR acceptance checklist

Edited by Marc Shaw

Merge request reports

Loading