2016-10-26 17:21:50 -04:00
|
|
|
module Issues
|
|
|
|
class BuildService < Issues::BaseService
|
2017-02-27 12:12:52 -05:00
|
|
|
include ResolveDiscussions
|
|
|
|
|
2016-10-26 17:21:50 -04:00
|
|
|
def execute
|
2017-02-27 12:12:52 -05:00
|
|
|
filter_resolve_discussion_params
|
2016-10-26 17:21:50 -04:00
|
|
|
@issue = project.issues.new(issue_params)
|
|
|
|
end
|
|
|
|
|
2016-12-22 07:31:12 -05:00
|
|
|
def issue_params_with_info_from_discussions
|
2017-03-10 03:19:12 -05:00
|
|
|
return {} unless merge_request_to_resolve_discussions_of
|
2016-10-26 17:21:50 -04:00
|
|
|
|
2017-03-07 18:00:21 -05:00
|
|
|
{ title: title_from_merge_request, description: description_for_discussions }
|
2016-10-26 17:21:50 -04:00
|
|
|
end
|
|
|
|
|
2017-03-07 18:00:21 -05:00
|
|
|
def title_from_merge_request
|
2017-03-10 03:19:12 -05:00
|
|
|
"Follow-up from \"#{merge_request_to_resolve_discussions_of.title}\""
|
2016-10-26 17:21:50 -04:00
|
|
|
end
|
|
|
|
|
2016-12-22 07:31:12 -05:00
|
|
|
def description_for_discussions
|
|
|
|
if discussions_to_resolve.empty?
|
2016-10-26 17:21:50 -04:00
|
|
|
return "There are no unresolved discussions. "\
|
2017-03-10 03:19:12 -05:00
|
|
|
"Review the conversation in #{merge_request_to_resolve_discussions_of.to_reference}"
|
2016-10-26 17:21:50 -04:00
|
|
|
end
|
|
|
|
|
2016-12-22 07:31:12 -05:00
|
|
|
description = "The following #{'discussion'.pluralize(discussions_to_resolve.size)} "\
|
2017-03-10 03:19:12 -05:00
|
|
|
"from #{merge_request_to_resolve_discussions_of.to_reference} "\
|
2016-12-22 07:31:12 -05:00
|
|
|
"should be addressed:"
|
|
|
|
|
2016-10-26 17:21:50 -04:00
|
|
|
[description, *items_for_discussions].join("\n\n")
|
|
|
|
end
|
|
|
|
|
|
|
|
def items_for_discussions
|
2016-12-22 07:31:12 -05:00
|
|
|
discussions_to_resolve.map { |discussion| item_for_discussion(discussion) }
|
2016-10-26 17:21:50 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def item_for_discussion(discussion)
|
2016-12-22 07:31:12 -05:00
|
|
|
first_note = discussion.first_note_to_resolve || discussion.first_note
|
2016-10-26 17:21:50 -04:00
|
|
|
other_note_count = discussion.notes.size - 1
|
|
|
|
note_url = Gitlab::UrlBuilder.build(first_note)
|
|
|
|
|
2017-03-10 07:05:35 -05:00
|
|
|
discussion_info = "- [ ] #{first_note.author.to_reference} commented on a [discussion](#{note_url}): "
|
2016-10-26 17:21:50 -04:00
|
|
|
discussion_info << " (+#{other_note_count} #{'comment'.pluralize(other_note_count)})" if other_note_count > 0
|
|
|
|
|
|
|
|
note_without_block_quotes = Banzai::Filter::BlockquoteFenceFilter.new(first_note.note).call
|
2017-03-07 18:55:50 -05:00
|
|
|
spaces = ' ' * 4
|
|
|
|
quote = note_without_block_quotes.lines.map { |line| "#{spaces}> #{line}" }.join
|
2016-10-26 17:21:50 -04:00
|
|
|
|
|
|
|
[discussion_info, quote].join("\n\n")
|
|
|
|
end
|
|
|
|
|
|
|
|
def issue_params
|
2016-12-22 07:31:12 -05:00
|
|
|
@issue_params ||= issue_params_with_info_from_discussions.merge(whitelisted_issue_params)
|
2017-01-28 19:14:56 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def whitelisted_issue_params
|
|
|
|
if can?(current_user, :admin_issue, project)
|
|
|
|
params.slice(:title, :description, :milestone_id)
|
|
|
|
else
|
|
|
|
params.slice(:title, :description)
|
|
|
|
end
|
2016-10-26 17:21:50 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|