Add 'Resolved all discussions' system note
This commit is contained in:
parent
220b82a40c
commit
fa4a613517
6 changed files with 28 additions and 0 deletions
|
@ -9,6 +9,8 @@ class Projects::DiscussionsController < Projects::ApplicationController
|
|||
|
||||
discussion.resolve!(current_user)
|
||||
|
||||
MergeRequests::AllDiscussionsResolvedService.new(project, current_user).execute(merge_request)
|
||||
|
||||
render json: {
|
||||
resolved_by: discussion.resolved_by.try(:name),
|
||||
discussion_headline_html: view_to_html_string('discussions/_headline', discussion: discussion)
|
||||
|
|
|
@ -72,6 +72,8 @@ class Projects::NotesController < Projects::ApplicationController
|
|||
|
||||
note.resolve!(current_user)
|
||||
|
||||
MergeRequests::AllDiscussionsResolvedService.new(project, current_user).execute(note.noteable)
|
||||
|
||||
discussion = note.discussion
|
||||
|
||||
render json: {
|
||||
|
|
|
@ -401,6 +401,11 @@ class MergeRequest < ActiveRecord::Base
|
|||
discussions
|
||||
end
|
||||
|
||||
def discussions_resolved?
|
||||
all_discussions = discussions
|
||||
all_discussions.any?(&:resolvable?) && all_discussions.none?(&:to_be_resolved?)
|
||||
end
|
||||
|
||||
def hook_attrs
|
||||
attrs = {
|
||||
source: source_project.try(:hook_attrs),
|
||||
|
|
|
@ -0,0 +1,9 @@
|
|||
module MergeRequests
|
||||
class AllDiscussionsResolvedService < MergeRequests::BaseService
|
||||
def execute(merge_request)
|
||||
return unless merge_request.discussions_resolved?
|
||||
|
||||
SystemNoteService.resolve_all_discussions(merge_request, project, current_user)
|
||||
end
|
||||
end
|
||||
end
|
|
@ -3,6 +3,10 @@ module Notes
|
|||
def execute(note)
|
||||
note.destroy
|
||||
note.reset_events_cache
|
||||
|
||||
if note.resolvable?
|
||||
MergeRequests::AllDiscussionsResolvedService.new(project, current_user).execute(note.noteable)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -156,6 +156,12 @@ class SystemNoteService
|
|||
create_note(noteable: noteable, project: project, author: author, note: body)
|
||||
end
|
||||
|
||||
def self.resolve_all_discussions(merge_request, project, author)
|
||||
body = "Resolved all discussions"
|
||||
|
||||
create_note(noteable: merge_request, project: project, author: author, note: body)
|
||||
end
|
||||
|
||||
# Called when the title of a Noteable is changed
|
||||
#
|
||||
# noteable - Noteable object that responds to `title`
|
||||
|
|
Loading…
Reference in a new issue