Commit 6700f226 authored by Stan Hu's avatar Stan Hu

Add a quick action for /rebase

This will make it easier for people to bring their merge requests
up-to-date.
parent 7d2741f9
......@@ -38,6 +38,37 @@ module Gitlab
@updates[:merge] = params[:merge_request_diff_head_sha]
end
types MergeRequest
desc do
_('Rebase source branch')
end
explanation do
_('Rebase source branch on the target branch.')
end
condition do
merge_request = quick_action_target
next false unless merge_request.source_branch_exists?
access_check = ::Gitlab::UserAccess
.new(current_user, container: merge_request.source_project)
access_check.can_push_to_branch?(merge_request.source_branch)
end
command :rebase do
result = MergeRequests::RebaseService.new(quick_action_target.project, current_user)
.execute(quick_action_target)
branch = quick_action_target.source_branch
@execution_message[:rebase] =
if result[:status] == :success
_('Scheduled a rebase of branch %{branch}.')
else
_('Failed to schedule a rebase of %{branch}.')
end % { branch: branch }
end
desc 'Toggle the Draft status'
explanation do
noun = quick_action_target.to_ability_name.humanize(capitalize: false)
......
......@@ -11880,6 +11880,9 @@ msgstr ""
msgid "Failed to save preferences."
msgstr ""
msgid "Failed to schedule a rebase of %{branch}."
msgstr ""
msgid "Failed to set due date because the date format is invalid."
msgstr ""
......@@ -22975,6 +22978,12 @@ msgstr ""
msgid "Rebase in progress"
msgstr ""
msgid "Rebase source branch"
msgstr ""
msgid "Rebase source branch on the target branch."
msgstr ""
msgid "Receive alerts from manually configured Prometheus servers."
msgstr ""
......@@ -24328,6 +24337,9 @@ msgstr ""
msgid "Scheduled Deletion At - %{permanent_deletion_time}"
msgstr ""
msgid "Scheduled a rebase of branch %{branch}."
msgstr ""
msgid "Scheduled to merge this merge request (%{strategy})."
msgstr ""
......
......@@ -41,5 +41,6 @@ RSpec.describe 'Merge request > User uses quick actions', :js do
end
it_behaves_like 'merge quick action'
it_behaves_like 'rebase quick action'
end
end
# frozen_string_literal: true
RSpec.shared_examples 'rebase quick action' do
context 'when updating the description' do
before do
sign_in(user)
visit edit_project_merge_request_path(project, merge_request)
end
it 'rebases the MR', :sidekiq_inline do
fill_in('Description', with: '/rebase')
click_button('Save changes')
expect(page).not_to have_content('commit behind the target branch')
expect(merge_request.reload).not_to be_merged
end
end
context 'when creating a new note' do
context 'when the current user can rebase the MR' do
before do
sign_in(user)
visit project_merge_request_path(project, merge_request)
end
it 'rebase the MR', :sidekiq_inline do
add_note("/rebase")
expect(page).to have_content "Scheduled a rebase of branch #{merge_request.source_branch}."
end
end
context 'when the current user cannot rebase the MR' do
before do
project.add_guest(guest)
sign_in(guest)
visit project_merge_request_path(project, merge_request)
end
it 'does not rebase the MR' do
add_note("/rebase")
expect(page).not_to have_content 'Your commands have been executed!'
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