Skip to content

fix: Determine need_rebase as not a mergeable status#5867

Merged
lukemassa merged 8 commits intorunatlantis:mainfrom
lukemassa:change_need_rebase_determination
Oct 9, 2025
Merged

fix: Determine need_rebase as not a mergeable status#5867
lukemassa merged 8 commits intorunatlantis:mainfrom
lukemassa:change_need_rebase_determination

Conversation

@lukemassa
Copy link
Contributor

@lukemassa lukemassa commented Oct 7, 2025

what

In Gitlab, make it so if a merge request is in status needs_rebase, then mark it as not mergeable.

why

Previously, when an MR was determined to be in the need_rebase status, we counted it as "mergeable", see #4402. Since then a number of bugs have been reported (#5826, #4025, #5124), indicating that users expect certain situations with need_rebase to be considered not mergeable.

I dug in a bit, and it looks like it depends on how you have your project configured. If your Merge Method is set to "Merge commit with semi-linear history" or "Fast-forward merge", then gitlab is explicitly saying your MR is not able to be merged like so:

Screenshot 2025-10-07 at 1 18 52 AM

Indeed, if you successfully apply and have automerge set, it will fail to merge, leaving you in a bad state.

Screenshot 2025-10-07 at 1 18 14 AM

The VCS itself pretty clearly indicates that a given MR is "unmergeable" we should follow suit

tests

I added some tests, and also tried this out on a test repo by setting a plan_requirement to mergeable and pushing a stale branch. You'll note that gitlab has noted the MR is not able to be merged, which is reflected in the new error message in the comment.

Screenshot 2025-10-08 at 8 32 46 PM

Note also that, even in newer versions, the API can respond with:

  "merge_status": "can_be_merged",
  "detailed_merge_status": "need_rebase",

merge_status was deprecated in 15.6 https://gitlab.com/gitlab-org/gitlab/-/issues/3169#note_1162532204; our code already detects version and uses detailed_merge_status if the server is new enough. However if it's not new enough we have to fall back to merge_status and we have no choice but to call such an MR "mergeable". This is reflected in the unit tests.

Note also that the unit tests were a bit broken; they included gitlabVersions in the test struct but never used it, always used the variable gitlabServerVersions. I fixed this and it allowed me to test different behavior for different versions (presumably) as intended.

references

closes: #5826, #4025, and #5124
functionally reverts: #4402

@github-actions github-actions bot added docs Documentation go Pull requests that update Go code provider/gitlab labels Oct 7, 2025
@dosubot dosubot bot added the bug Something isn't working label Oct 7, 2025
Signed-off-by: Luke Massa <lukefrederickmassa@gmail.com>
Signed-off-by: Luke Massa <lukefrederickmassa@gmail.com>
@lukemassa lukemassa force-pushed the change_need_rebase_determination branch from 0747032 to 2b91fea Compare October 8, 2025 01:13
Signed-off-by: Luke Massa <lukefrederickmassa@gmail.com>
Signed-off-by: Luke Massa <lukefrederickmassa@gmail.com>
@lukemassa lukemassa force-pushed the change_need_rebase_determination branch from 8b58836 to 766e531 Compare October 8, 2025 01:27
Signed-off-by: Luke Massa <lukefrederickmassa@gmail.com>
@lukemassa lukemassa changed the title fix: Change how IsMergeable is determined in gitlab when merge request is need_rebase fix: Determine need_rebase as not a mergeable status Oct 8, 2025
@lukemassa lukemassa marked this pull request as draft October 8, 2025 01:44
Signed-off-by: Luke Massa <lukefrederickmassa@gmail.com>
@lukemassa lukemassa marked this pull request as ready for review October 8, 2025 02:52
chenrui333
chenrui333 previously approved these changes Oct 8, 2025
@dosubot dosubot bot added the lgtm This PR has been approved by a maintainer label Oct 8, 2025
@chenrui333 chenrui333 requested a review from Copilot October 8, 2025 15:00
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR fixes a bug where GitLab merge requests with need_rebase status were incorrectly considered mergeable, when they should be marked as not mergeable for certain GitLab project configurations.

  • Updates the gitlabIsMergeable function to exclude need_rebase from mergeable statuses
  • Adds comprehensive test cases to handle version differences (pre and post GitLab 15.6)
  • Updates documentation to clarify GitLab mergeability requirements

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
server/events/vcs/gitlab_client.go Removes need_rebase from the list of mergeable statuses
server/events/vcs/gitlab_client_test.go Fixes test structure and adds new test cases for different GitLab versions
runatlantis.io/docs/command-requirements.md Updates documentation to clarify GitLab merge requirements

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Signed-off-by: Luke Massa <lukefrederickmassa@gmail.com>
@lukemassa lukemassa merged commit 0a6701f into runatlantis:main Oct 9, 2025
41 checks passed
ramonvermeulen pushed a commit to bschaatsbergen/atlantis that referenced this pull request Oct 13, 2025
Signed-off-by: Luke Massa <lukefrederickmassa@gmail.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Signed-off-by: Ramon Vermeulen <ramonvermeulen98@gmail.com>
dimisjim pushed a commit to dimisjim/atlantis that referenced this pull request Oct 29, 2025
Signed-off-by: Luke Massa <lukefrederickmassa@gmail.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Signed-off-by: dimisjim <dimitris.moraitidis@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working docs Documentation go Pull requests that update Go code lgtm This PR has been approved by a maintainer provider/gitlab

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Atlantis applies plan even if merge request needs rebase (GitLab)

3 participants