Skip to content

Fix auto-merge on incomplete pipelines

What does this MR do and why?

This fixes the following omissions in the initial implementation of the expansion of auto-merge to merge requests with incomplete diff head pipelines:

  1. The "when pipeline succeeds" auto-merge variants should only be available on blocked statuses if "Pipelines must succeed" is enabled. Otherwise, standard merges should be the default. When pipelines are not required to succeed, we only expand auto-merge to the created status.
  2. In particular, when merge trains are enabled but pipelines are not required to succeed, the auto-merge action should simply be "Add to merge train".

Also included in this change are two fixes related to the "Merge immediately" dropdown:

  1. Use this.isAutoMergeAvailable instead of this.isPipelineActive to determine whether the dropdown should show, becauase the backend already checks the pipeline state when deciding whether a given auto merge service is available.
  2. Fixed the dropdown behaviour for fast-forward and semi-linear merge trains. Immediate merges should always be conditional on "Pipelines must succeed" being disabled, and the fast-forward check should also apply to the "when pipeline succeeds" variant.

MR acceptance checklist

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

Screenshots or screen recordings

Screenshots are required for UI changes, and strongly recommended for all other merge requests.

Merge trains Pipelines must succeed Before After
disabled disabled 000-flag-disabled-train-disabled-pipeline-must-succeed-disabled 100-flag-enabled-train-disabled-pipeline-must-succeed-disabled
disabled enabled 001-flag-disabled-train-disabled-pipeline-must-succeed-enabled 101-flag-enabled-train-disabled-pipeline-must-succeed-enabled
enabled disabled 010-flag-disabled-train-enabled-pipeline-must-succeed-disabled 110-flag-enabled-train-enabled-pipeline-must-succeed-disabled
enabled enabled 011-flag-disabled-train-enabled-pipeline-must-succeed-enabled 111-flag-enabled-train-enabled-pipeline-must-succeed-enabled

How to set up and validate locally

  1. Enable the flag auto_merge_when_incomplete_pipeline_succeeds:

    Feature.enable(:auto_merge_when_incomplete_pipeline_succeeds)

    In a project, create a merge request changing the .gitlab-ci.yml to

    workflow:
      rules:
        - if: $CI_MERGE_REQUEST_IID
        - if: $CI_COMMIT_TAG
        - if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
    
     test:
       script: echo hi
       when: manual
       allow_failure: false
  2. Observe that the merge action is an auto-merge instead of an immediate merge.

  3. Set the MR to auto merge

  4. Run the pipeline

  5. Observe that it merges

Test with any combination of the following variants:

  • Enable / disable the Pipelines must succeed
  • Enable / disable merge trains
  • Change the merge method
  • Test with other pipeline statuses (e.g. running, succeeded)
Edited by Hordur Freyr Yngvason

Merge request reports