2018-07-16 12:31:01 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-11-01 13:35:14 -04:00
|
|
|
module Issuable
|
|
|
|
class CommonSystemNotesService < ::BaseService
|
|
|
|
attr_reader :issuable
|
|
|
|
|
2020-05-14 11:08:14 -04:00
|
|
|
def execute(issuable, old_labels: [], old_milestone: nil, is_update: true)
|
2017-11-01 13:35:14 -04:00
|
|
|
@issuable = issuable
|
|
|
|
|
2019-11-21 04:06:16 -05:00
|
|
|
# We disable touch so that created system notes do not update
|
|
|
|
# the noteable's updated_at field
|
|
|
|
ActiveRecord::Base.no_touching do
|
|
|
|
if is_update
|
|
|
|
if issuable.previous_changes.include?('title')
|
|
|
|
create_title_change_note(issuable.previous_changes['title'].first)
|
|
|
|
end
|
|
|
|
|
|
|
|
handle_description_change_note
|
|
|
|
|
|
|
|
handle_time_tracking_note if issuable.is_a?(TimeTrackable)
|
|
|
|
create_discussion_lock_note if issuable.previous_changes.include?('discussion_locked')
|
2018-12-16 23:35:59 -05:00
|
|
|
end
|
2017-11-01 13:35:14 -04:00
|
|
|
|
2019-11-21 04:06:16 -05:00
|
|
|
create_due_date_note if issuable.previous_changes.include?('due_date')
|
2020-09-03 02:08:22 -04:00
|
|
|
create_milestone_change_event(old_milestone) if issuable.previous_changes.include?('milestone_id')
|
2019-11-21 04:06:16 -05:00
|
|
|
create_labels_note(old_labels) if old_labels && issuable.labels != old_labels
|
2018-12-16 23:35:59 -05:00
|
|
|
end
|
2017-11-01 13:35:14 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def handle_time_tracking_note
|
|
|
|
if issuable.previous_changes.include?('time_estimate')
|
|
|
|
create_time_estimate_note
|
|
|
|
end
|
|
|
|
|
|
|
|
if issuable.time_spent?
|
|
|
|
create_time_spent_note
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def handle_description_change_note
|
|
|
|
if issuable.previous_changes.include?('description')
|
|
|
|
if issuable.tasks? && issuable.updated_tasks.any?
|
|
|
|
create_task_status_note
|
|
|
|
else
|
|
|
|
# TODO: Show this note if non-task content was modified.
|
2019-09-18 10:02:45 -04:00
|
|
|
# https://gitlab.com/gitlab-org/gitlab-foss/issues/33577
|
2017-11-01 13:35:14 -04:00
|
|
|
create_description_change_note
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-10-26 11:08:40 -04:00
|
|
|
def create_draft_note(old_title)
|
2017-11-21 14:25:37 -05:00
|
|
|
return unless issuable.is_a?(MergeRequest)
|
|
|
|
|
|
|
|
if MergeRequest.work_in_progress?(old_title) != issuable.work_in_progress?
|
2020-10-26 11:08:40 -04:00
|
|
|
SystemNoteService.handle_merge_request_draft(issuable, issuable.project, current_user)
|
2017-11-21 14:25:37 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-11-01 13:35:14 -04:00
|
|
|
def create_labels_note(old_labels)
|
|
|
|
added_labels = issuable.labels - old_labels
|
|
|
|
removed_labels = old_labels - issuable.labels
|
|
|
|
|
2018-09-07 09:39:20 -04:00
|
|
|
ResourceEvents::ChangeLabelsService
|
|
|
|
.new(issuable, current_user)
|
|
|
|
.execute(added_labels: added_labels, removed_labels: removed_labels)
|
2017-11-01 13:35:14 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def create_title_change_note(old_title)
|
2020-10-26 11:08:40 -04:00
|
|
|
create_draft_note(old_title)
|
2017-11-21 14:25:37 -05:00
|
|
|
|
|
|
|
if issuable.wipless_title_changed(old_title)
|
|
|
|
SystemNoteService.change_title(issuable, issuable.project, current_user, old_title)
|
|
|
|
end
|
2017-11-01 13:35:14 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def create_description_change_note
|
|
|
|
SystemNoteService.change_description(issuable, issuable.project, current_user)
|
|
|
|
end
|
|
|
|
|
|
|
|
def create_task_status_note
|
|
|
|
issuable.updated_tasks.each do |task|
|
|
|
|
SystemNoteService.change_task_status(issuable, issuable.project, current_user, task)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def create_time_estimate_note
|
|
|
|
SystemNoteService.change_time_estimate(issuable, issuable.project, current_user)
|
|
|
|
end
|
|
|
|
|
|
|
|
def create_time_spent_note
|
|
|
|
SystemNoteService.change_time_spent(issuable, issuable.project, issuable.time_spent_user)
|
|
|
|
end
|
|
|
|
|
2020-05-14 11:08:14 -04:00
|
|
|
def create_milestone_change_event(old_milestone)
|
|
|
|
ResourceEvents::ChangeMilestoneService.new(issuable, current_user, old_milestone: old_milestone)
|
|
|
|
.execute
|
|
|
|
end
|
|
|
|
|
2018-09-09 14:08:21 -04:00
|
|
|
def create_due_date_note
|
|
|
|
SystemNoteService.change_due_date(issuable, issuable.project, current_user, issuable.due_date)
|
|
|
|
end
|
|
|
|
|
2017-11-01 13:35:14 -04:00
|
|
|
def create_discussion_lock_note
|
|
|
|
SystemNoteService.discussion_lock(issuable, current_user)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2019-09-13 09:26:31 -04:00
|
|
|
|
|
|
|
Issuable::CommonSystemNotesService.prepend_if_ee('EE::Issuable::CommonSystemNotesService')
|