Execute quick actions when creating MR from issue

In CE, this does nothing - the `MergeRequests::BuildService` will, at the time
of writing, never return a description for this case.

In EE, a project can have a default MR template, which will be returned by the
service. Previously we were only using the description passed in the params,
ignoring any already set on the object. Now we fall back to the one set on the
object if there was none in the params, allowing quick actions to be executed
from default MR templates when creating an MR from an issue.
This commit is contained in:
Sean McGivern 2017-12-08 13:34:54 +00:00
parent 9429e8ac60
commit b1e3cb24fa
3 changed files with 21 additions and 2 deletions

View File

@ -106,12 +106,14 @@ class IssuableBaseService < BaseService
end
def merge_quick_actions_into_params!(issuable)
original_description = params.fetch(:description, issuable.description)
description, command_params =
QuickActions::InterpretService.new(project, current_user)
.execute(params[:description], issuable)
.execute(original_description, issuable)
# Avoid a description already set on an issuable to be overwritten by a nil
params[:description] = description if params.key?(:description)
params[:description] = description if description
params.merge!(command_params)
end

View File

@ -0,0 +1,5 @@
---
title: Execute quick actions (if present) when creating MR from issue
merge_request: 15810
author:
type: fixed

View File

@ -100,5 +100,17 @@ describe MergeRequests::CreateFromIssueService do
expect(result[:merge_request].target_branch).to eq(project.default_branch)
end
it 'executes quick actions if the build service sets them in the description' do
allow(service).to receive(:merge_request).and_wrap_original do |m, *args|
m.call(*args).tap do |merge_request|
merge_request.description = "/assign #{user.to_reference}"
end
end
result = service.execute
expect(result[:merge_request].assignee).to eq(user)
end
end
end