Commit 53c9af39 authored by Stan Hu's avatar Stan Hu

Avoid 409 StaleObjectError errors with /rebase

If a merge request is closed, the quick action /rebase will quietly fail
with a 409 StaleObjectError. To avoid that, we disable this quick action
if the merge request is closed.

If a rebase is in progress, the quick action will also fail with the
same error. We now check the state and report to the user that the
rebase is in progress.

Relates to https://gitlab.com/gitlab-org/gitlab/-/issues/296223
parent a6994188
---
title: Avoid 409 StaleObjectError errors with /rebase
merge_request: 50719
author:
type: fixed
......@@ -48,6 +48,7 @@ module Gitlab
condition do
merge_request = quick_action_target
next false unless merge_request.open?
next false unless merge_request.source_branch_exists?
access_check = ::Gitlab::UserAccess
......@@ -56,6 +57,11 @@ module Gitlab
access_check.can_push_to_branch?(merge_request.source_branch)
end
command :rebase do
if quick_action_target.rebase_in_progress?
@execution_message[:rebase] = _('A rebase is already in progress.')
next
end
# This will be used to avoid simultaneous "/merge" and "/rebase" actions
@updates[:rebase] = true
......
......@@ -1322,6 +1322,9 @@ msgstr ""
msgid "A ready-to-go template for use with iOS Swift apps"
msgstr ""
msgid "A rebase is already in progress."
msgstr ""
msgid "A regular expression that will be used to find the test coverage output in the job log. Leave blank to disable"
msgstr ""
......
......@@ -36,6 +36,33 @@ RSpec.shared_examples 'rebase quick action' do
expect(page).to have_content "Scheduled a rebase of branch #{merge_request.source_branch}."
end
context 'when the merge request is closed' do
before do
merge_request.close!
end
it 'does not rebase the MR', :sidekiq_inline do
add_note("/rebase")
expect(page).not_to have_content 'Scheduled a rebase'
end
end
context 'when a rebase is in progress', :sidekiq_inline, :clean_gitlab_redis_shared_state do
before do
jid = SecureRandom.hex
merge_request.update!(rebase_jid: jid)
Gitlab::SidekiqStatus.set(jid)
end
it 'tells the user a rebase is in progress' do
add_note('/rebase')
expect(page).to have_content 'A rebase is already in progress.'
expect(page).not_to have_content 'Scheduled a rebase'
end
end
end
context 'when the current user cannot rebase the MR' do
......@@ -48,7 +75,7 @@ RSpec.shared_examples 'rebase quick action' do
it 'does not rebase the MR' do
add_note("/rebase")
expect(page).not_to have_content 'Your commands have been executed!'
expect(page).not_to have_content 'Scheduled a rebase'
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