Commit e3d464d8 authored by Rémy Coutable's avatar Rémy Coutable

Fix a wrong MR status when merge_when_build_succeeds &...

Fix a wrong MR status when merge_when_build_succeeds & project.only_allow_merge_if_build_succeeds are true

The issue was that `MergeRequest#mergeable?` returns false when the CI
state is not success and project.only_allow_merge_if_build_succeeds is
true. In this case `Projects::MergeRequestsController#merge` would
return the `:failed` status when enabling `merge_when_build_succeeds`,
thus leading to a weird state and the MR never automatically merged.

The fix is to disable the CI state check in the controller safeguard
that early return the `:failed` status.
Signed-off-by: default avatarRémy Coutable <remy@rymai.me>
parent dbbc3594
......@@ -22,6 +22,7 @@ v 8.9.1
- Fix mobile Safari bug where horizontal nav arrows would flicker on scroll
- Fix in auto merge when pipeline is nil
- Fix GitLab import project deleting imported file straight after being uploaded
- Fix a wrong MR status when merge_when_build_succeeds & project.only_allow_merge_if_build_succeeds are true
v 8.9.0
- Fix builds API response not including commit data
......
......@@ -199,7 +199,9 @@ class Projects::MergeRequestsController < Projects::ApplicationController
def merge
return access_denied! unless @merge_request.can_be_merged_by?(current_user)
unless @merge_request.mergeable?
# Disable the CI check if merge_when_build_succeeds is enabled since we have
# to wait until CI completes to know
unless @merge_request.mergeable?(skip_ci_check: merge_when_build_succeeds_active?)
@status = :failed
return
end
......@@ -395,4 +397,9 @@ class Projects::MergeRequestsController < Projects::ApplicationController
def ensure_ref_fetched
@merge_request.ensure_ref_fetched
end
def merge_when_build_succeeds_active?
params[:merge_when_build_succeeds].present? &&
@merge_request.pipeline && @merge_request.pipeline.active?
end
end
......@@ -264,19 +264,19 @@ class MergeRequest < ActiveRecord::Base
self.title.sub(WIP_REGEX, "")
end
def mergeable?
return false unless mergeable_state?
def mergeable?(skip_ci_check: false)
return false unless mergeable_state?(skip_ci_check: skip_ci_check)
check_if_can_be_merged
can_be_merged?
end
def mergeable_state?
def mergeable_state?(skip_ci_check: false)
return false unless open?
return false if work_in_progress?
return false if broken?
return false unless mergeable_ci_state?
return false unless skip_ci_check || mergeable_ci_state?
true
end
......
......@@ -264,6 +264,18 @@ describe Projects::MergeRequestsController do
merge_when_build_succeeds
end
context 'when project.only_allow_merge_if_build_succeeds? is true' do
before do
project.update_column(:only_allow_merge_if_build_succeeds, true)
end
it 'returns :merge_when_build_succeeds' do
merge_when_build_succeeds
expect(assigns(:status)).to eq(:merge_when_build_succeeds)
end
end
end
end
end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment