Commit 2f5ba074 authored by Bob Van Landuyt's avatar Bob Van Landuyt

Build issues for merge request when there is an issue template

parent 37a1fd6d
...@@ -77,11 +77,6 @@ class Projects::IssuesController < Projects::ApplicationController ...@@ -77,11 +77,6 @@ class Projects::IssuesController < Projects::ApplicationController
@merge_request_to_resolve_discussions_of = service.merge_request_to_resolve_discussions_of @merge_request_to_resolve_discussions_of = service.merge_request_to_resolve_discussions_of
@discussion_to_resolve = service.discussions_to_resolve.first if params[:discussion_to_resolve] @discussion_to_resolve = service.discussions_to_resolve.first if params[:discussion_to_resolve]
# Set Issue description based on project template
if @project.issues_template.present?
@issue.description = @project.issues_template
end
respond_with(@issue) respond_with(@issue)
end end
......
...@@ -7,6 +7,10 @@ module Issues ...@@ -7,6 +7,10 @@ module Issues
@issue = project.issues.new(issue_params) @issue = project.issues.new(issue_params)
end end
def issue_params_from_template
{ description: project.issues_template }
end
def issue_params_with_info_from_discussions def issue_params_with_info_from_discussions
return {} unless merge_request_to_resolve_discussions_of return {} unless merge_request_to_resolve_discussions_of
...@@ -49,8 +53,13 @@ module Issues ...@@ -49,8 +53,13 @@ module Issues
[discussion_info, quote].join("\n\n") [discussion_info, quote].join("\n\n")
end end
# Issue params can be built from 3 types of passed params,
# They take precedence over eachother like this
# passed params > discussion params > template params
def issue_params def issue_params
@issue_params ||= issue_params_with_info_from_discussions.merge(whitelisted_issue_params) @issue_params ||= issue_params_from_template.
merge(issue_params_with_info_from_discussions).
merge(whitelisted_issue_params)
end end
def whitelisted_issue_params def whitelisted_issue_params
......
...@@ -8,6 +8,19 @@ describe Issues::BuildService, services: true do ...@@ -8,6 +8,19 @@ describe Issues::BuildService, services: true do
project.team << [user, :developer] project.team << [user, :developer]
end end
context 'with an issue template' do
describe '#execute' do
it 'fills in the template in the description' do
project = build(:project, issues_template: 'Work hard, play hard!')
service = described_class.new(project, user)
issue = service.execute
expect(issue.description).to eq('Work hard, play hard!')
end
end
end
context 'for a single discussion' do context 'for a single discussion' do
describe '#execute' do describe '#execute' do
let(:merge_request) { create(:merge_request, title: "Hello world", source_project: project) } let(:merge_request) { create(:merge_request, title: "Hello world", source_project: project) }
...@@ -25,6 +38,16 @@ describe Issues::BuildService, services: true do ...@@ -25,6 +38,16 @@ describe Issues::BuildService, services: true do
expect(issue.description).to include('Almost done') expect(issue.description).to include('Almost done')
end end
context 'with an issue template' do
let(:project) { create(:project, :repository, issues_template: 'Work hard, play hard!') }
it 'picks the discussion description over the issue template' do
issue = service.execute
expect(issue.description).to include('Almost done')
end
end
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