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

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

[port] New `/wip` quick action on MR creation

See merge request gitlab-org/gitlab-ee!4790
parents c8960cd9 8c10a208
......@@ -111,6 +111,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)
......@@ -133,7 +137,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)
......
......@@ -26,6 +26,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
......
......@@ -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)
......
......@@ -119,17 +119,6 @@ module MergeRequests
end
end
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,
......
......@@ -348,9 +348,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'
......
---
title: Port /wip quick action command to Merge Request creation (on description)
merge_request: 17463
author: Adam Pahlevi
type: added
......@@ -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
{
......
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