diff options
-rw-r--r-- | app/controllers/projects/discussions_controller.rb | 2 | ||||
-rw-r--r-- | app/controllers/projects/notes_controller.rb | 2 | ||||
-rw-r--r-- | app/models/merge_request.rb | 5 | ||||
-rw-r--r-- | app/services/merge_requests/all_discussions_resolved_service.rb | 9 | ||||
-rw-r--r-- | app/services/notes/delete_service.rb | 4 | ||||
-rw-r--r-- | app/services/system_note_service.rb | 6 |
6 files changed, 28 insertions, 0 deletions
diff --git a/app/controllers/projects/discussions_controller.rb b/app/controllers/projects/discussions_controller.rb index 11c8f714a95..86e3f865c6f 100644 --- a/app/controllers/projects/discussions_controller.rb +++ b/app/controllers/projects/discussions_controller.rb @@ -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) diff --git a/app/controllers/projects/notes_controller.rb b/app/controllers/projects/notes_controller.rb index 027a2d7dcb2..1849311d26d 100644 --- a/app/controllers/projects/notes_controller.rb +++ b/app/controllers/projects/notes_controller.rb @@ -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: { diff --git a/app/models/merge_request.rb b/app/models/merge_request.rb index 04cec923f2e..484e37ff31a 100644 --- a/app/models/merge_request.rb +++ b/app/models/merge_request.rb @@ -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), diff --git a/app/services/merge_requests/all_discussions_resolved_service.rb b/app/services/merge_requests/all_discussions_resolved_service.rb new file mode 100644 index 00000000000..d0fe226c196 --- /dev/null +++ b/app/services/merge_requests/all_discussions_resolved_service.rb @@ -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 diff --git a/app/services/notes/delete_service.rb b/app/services/notes/delete_service.rb index 7f1b30ec84e..40d519cdf66 100644 --- a/app/services/notes/delete_service.rb +++ b/app/services/notes/delete_service.rb @@ -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 diff --git a/app/services/system_note_service.rb b/app/services/system_note_service.rb index 1ab3b5789bc..a9d5bad5122 100644 --- a/app/services/system_note_service.rb +++ b/app/services/system_note_service.rb @@ -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` |