From b1e3cb24fa777bc6776c7602935876f546383a38 Mon Sep 17 00:00:00 2001 From: Sean McGivern Date: Fri, 8 Dec 2017 13:34:54 +0000 Subject: [PATCH] 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. --- app/services/issuable_base_service.rb | 6 ++++-- .../fix-create-mr-from-issue-with-template.yml | 5 +++++ .../merge_requests/create_from_issue_service_spec.rb | 12 ++++++++++++ 3 files changed, 21 insertions(+), 2 deletions(-) create mode 100644 changelogs/unreleased/fix-create-mr-from-issue-with-template.yml diff --git a/app/services/issuable_base_service.rb b/app/services/issuable_base_service.rb index 2c51ac13815..e7463e6e25c 100644 --- a/app/services/issuable_base_service.rb +++ b/app/services/issuable_base_service.rb @@ -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 diff --git a/changelogs/unreleased/fix-create-mr-from-issue-with-template.yml b/changelogs/unreleased/fix-create-mr-from-issue-with-template.yml new file mode 100644 index 00000000000..8668aa18669 --- /dev/null +++ b/changelogs/unreleased/fix-create-mr-from-issue-with-template.yml @@ -0,0 +1,5 @@ +--- +title: Execute quick actions (if present) when creating MR from issue +merge_request: 15810 +author: +type: fixed diff --git a/spec/services/merge_requests/create_from_issue_service_spec.rb b/spec/services/merge_requests/create_from_issue_service_spec.rb index a7ab389b357..623b182b205 100644 --- a/spec/services/merge_requests/create_from_issue_service_spec.rb +++ b/spec/services/merge_requests/create_from_issue_service_spec.rb @@ -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