Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Apply Failed: Pull request must be mergeable before running apply. (gitlab) #4949

Open
kunal2791 opened this issue Sep 25, 2024 · 1 comment
Labels
bug Something isn't working provider/gitlab

Comments

@kunal2791
Copy link

Atlantis failing to properly detect GitLab Merge Requests (MR) as mergeable, even when they meet the criteria (such as pipeline passed, approvals received, and no conflicts).

if apply_requirement set to mergeable.

this is config file.

repos:

  • id: "/.*/"
    allowed_overrides: [workflow]
    pre_workflow_hooks:
    • run: rm -rf ~/.kube
    • run: tac_wrapper
      #post_workflow_hooks:
      #- run: '[ -f atlantis.yaml ] && { rm atlantis.yaml && echo "File deleted."; } || echo "Not found"'
      workflow: terragrunt
      delete_source_branch_on_merge: true
      apply_requirements: [mergeable]
      workflows:
      terragrunt:
      plan:
      steps:
      • run: rm -rf .terragrunt-cache
      • run: terragrunt plan
        apply:
        steps:
      • run: terragrunt apply
@kunal2791 kunal2791 added the bug Something isn't working label Sep 25, 2024
Copy link

dosubot bot commented Sep 25, 2024

Hey @kunal2791! I'm here to help you with your GitLab Merge Requests issue. I can assist with bug fixes, answer your questions, and guide you on how to become a contributor. Let's get this sorted out!

Atlantis might be failing to detect GitLab Merge Requests (MR) as mergeable due to several conditions that need to be met. The PullIsMergeable function in Atlantis checks various criteria, including the status of the pipeline, the merge request's detailed merge status, approvals, blocking discussions, and whether the merge request is a work in progress.

Here is a relevant code snippet from the PullIsMergeable function:

if ((supportsDetailedMergeStatus &&
    (mr.DetailedMergeStatus == "mergeable" ||
        mr.DetailedMergeStatus == "ci_still_running" ||
        mr.DetailedMergeStatus == "ci_must_pass" ||
        mr.DetailedMergeStatus == "need_rebase")) ||
    (!supportsDetailedMergeStatus &&
        mr.MergeStatus == "can_be_merged")) && //nolint:staticcheck // Need to reference deprecated field for backwards compatibility
    mr.ApprovalsBeforeMerge <= 0 &&
    mr.BlockingDiscussionsResolved &&
    !mr.WorkInProgress &&
    (allowSkippedPipeline || !isPipelineSkipped) {

    logger.Debug("Merge request is mergeable")
    return true, nil
}
logger.Debug("Merge request is not mergeable")
return false, nil

If any of these conditions are not met, the merge request will not be considered mergeable by Atlantis [1].

Additionally, there are similar issues reported by other users:

  1. Gitlab MR with approvals_before_merge > 0 causes issues with mergeable requirement - This issue suggests that Atlantis checks the wrong GitLab resource for approvals. It should check the approvals_left field instead of approvals_before_merge [2].
  2. Atlantis apply succeeds on unmergeable MR with apply_requirements mergeable in Gitlab - This issue was reproduced and confirmed to fail correctly in version v0.28.5 of Atlantis [3].
  3. Preventing merging without running atlantis apply on Gitlab - This issue discusses adding commit status updates to ensure proper mergeability checks [4].

You might want to verify if the approvals_left field is being checked correctly and ensure that all other conditions in the PullIsMergeable function are met.

To continue talking to Dosu, mention @dosu.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working provider/gitlab
Projects
None yet
Development

No branches or pull requests

1 participant