Merge branch 'wip-slash-command-on-mr-description' into 'master'

New `/wip` quick action on MR creation

Closes #26848

See merge request gitlab-org/gitlab-ce!17463
This commit is contained in:
Rémy Coutable 2018-03-05 15:34:13 +00:00
commit fa1debefe7
7 changed files with 64 additions and 15 deletions

View file

@ -109,6 +109,10 @@ class IssuableBaseService < BaseService
@available_labels ||= LabelsFinder.new(current_user, project_id: @project.id).execute
end
def handle_quick_actions_on_create(issuable)
merge_quick_actions_into_params!(issuable)
end
def merge_quick_actions_into_params!(issuable)
original_description = params.fetch(:description, issuable.description)
@ -131,7 +135,7 @@ class IssuableBaseService < BaseService
end
def create(issuable)
merge_quick_actions_into_params!(issuable)
handle_quick_actions_on_create(issuable)
filter_params(issuable)
params.delete(:state_event)

View file

@ -24,6 +24,17 @@ module MergeRequests
private
def handle_wip_event(merge_request)
if wip_event = params.delete(:wip_event)
# We update the title that is provided in the params or we use the mr title
title = params[:title] || merge_request.title
params[:title] = case wip_event
when 'wip' then MergeRequest.wip_title(title)
when 'unwip' then MergeRequest.wipless_title(title)
end
end
end
def merge_request_metrics_service(merge_request)
MergeRequestMetricsService.new(merge_request.metrics)
end

View file

@ -34,6 +34,12 @@ module MergeRequests
super
end
# Override from IssuableBaseService
def handle_quick_actions_on_create(merge_request)
super
handle_wip_event(merge_request)
end
private
def update_merge_requests_head_pipeline(merge_request)

View file

@ -98,17 +98,6 @@ module MergeRequests
private
def handle_wip_event(merge_request)
if wip_event = params.delete(:wip_event)
# We update the title that is provided in the params or we use the mr title
title = params[:title] || merge_request.title
params[:title] = case wip_event
when 'wip' then MergeRequest.wip_title(title)
when 'unwip' then MergeRequest.wipless_title(title)
end
end
end
def create_branch_change_note(issuable, branch_type, old_branch, new_branch)
SystemNoteService.change_branch(
issuable, issuable.project, current_user, branch_type,

View file

@ -347,9 +347,9 @@ module QuickActions
"#{verb} this #{noun} as Work In Progress."
end
condition do
issuable.persisted? &&
issuable.respond_to?(:work_in_progress?) &&
current_user.can?(:"update_#{issuable.to_ability_name}", issuable)
issuable.respond_to?(:work_in_progress?) &&
# Allow it to mark as WIP on MR creation page _or_ through MR notes.
(issuable.new_record? || current_user.can?(:"update_#{issuable.to_ability_name}", issuable))
end
command :wip do
@updates[:wip_event] = issuable.work_in_progress? ? 'unwip' : 'wip'

View file

@ -0,0 +1,4 @@
title: Port /wip quick action command to Merge Request creation (on description)
merge_request: 17463
author: Adam Pahlevi
type: added

View file

@ -28,6 +28,7 @@ describe MergeRequests::CreateService do
it 'creates an MR' do
expect(merge_request).to be_valid
expect(merge_request.work_in_progress?).to be(false)
expect(merge_request.title).to eq('Awesome merge_request')
expect(merge_request.assignee).to be_nil
expect(merge_request.merge_params['force_remove_source_branch']).to eq('1')
@ -62,6 +63,40 @@ describe MergeRequests::CreateService do
expect(Event.where(attributes).count).to eq(1)
end
describe 'when marked with /wip' do
context 'in title and in description' do
let(:opts) do
{
title: 'WIP: Awesome merge_request',
description: "well this is not done yet\n/wip",
source_branch: 'feature',
target_branch: 'master',
assignee: assignee
}
end
it 'sets MR to WIP' do
expect(merge_request.work_in_progress?).to be(true)
end
end
context 'in description only' do
let(:opts) do
{
title: 'Awesome merge_request',
description: "well this is not done yet\n/wip",
source_branch: 'feature',
target_branch: 'master',
assignee: assignee
}
end
it 'sets MR to WIP' do
expect(merge_request.work_in_progress?).to be(true)
end
end
end
context 'when merge request is assigned to someone' do
let(:opts) do
{