debian-mirror-gitlab/app/services/issuable/common_system_notes_service.rb

125 lines
3.9 KiB
Ruby
Raw Normal View History

2018-11-18 11:00:15 +05:30
# frozen_string_literal: true
2018-03-17 18:26:18 +05:30
module Issuable
class CommonSystemNotesService < ::BaseService
attr_reader :issuable
2019-02-15 15:39:39 +05:30
def execute(issuable, old_labels: [], is_update: true)
2018-03-17 18:26:18 +05:30
@issuable = issuable
2020-01-01 13:55:28 +05:30
# 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')
2019-02-15 15:39:39 +05:30
end
2018-03-17 18:26:18 +05:30
2020-01-01 13:55:28 +05:30
create_due_date_note if issuable.previous_changes.include?('due_date')
2020-04-08 14:13:33 +05:30
create_milestone_note if has_milestone_changes?
2020-01-01 13:55:28 +05:30
create_labels_note(old_labels) if old_labels && issuable.labels != old_labels
2019-02-15 15:39:39 +05:30
end
2018-03-17 18:26:18 +05:30
end
private
2020-04-08 14:13:33 +05:30
def has_milestone_changes?
issuable.previous_changes.include?('milestone_id')
end
2018-03-17 18:26:18 +05:30
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-12-04 20:38:33 +05:30
# https://gitlab.com/gitlab-org/gitlab-foss/issues/33577
2018-03-17 18:26:18 +05:30
create_description_change_note
end
end
end
def create_wip_note(old_title)
return unless issuable.is_a?(MergeRequest)
if MergeRequest.work_in_progress?(old_title) != issuable.work_in_progress?
SystemNoteService.handle_merge_request_wip(issuable, issuable.project, current_user)
end
end
def create_labels_note(old_labels)
added_labels = issuable.labels - old_labels
removed_labels = old_labels - issuable.labels
2018-11-20 20:47:30 +05:30
ResourceEvents::ChangeLabelsService
.new(issuable, current_user)
.execute(added_labels: added_labels, removed_labels: removed_labels)
2018-03-17 18:26:18 +05:30
end
def create_title_change_note(old_title)
create_wip_note(old_title)
if issuable.wipless_title_changed(old_title)
SystemNoteService.change_title(issuable, issuable.project, current_user, old_title)
end
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
def create_milestone_note
2020-04-08 14:13:33 +05:30
if milestone_changes_tracking_enabled?
# Creates a synthetic note
ResourceEvents::ChangeMilestoneService.new(issuable, current_user).execute
else
SystemNoteService.change_milestone(issuable, issuable.project, current_user, issuable.milestone)
end
end
def milestone_changes_tracking_enabled?
::Feature.enabled?(:track_resource_milestone_change_events, issuable.project)
2018-03-17 18:26:18 +05:30
end
2018-11-20 20:47:30 +05:30
def create_due_date_note
SystemNoteService.change_due_date(issuable, issuable.project, current_user, issuable.due_date)
end
2018-03-17 18:26:18 +05:30
def create_discussion_lock_note
SystemNoteService.discussion_lock(issuable, current_user)
end
end
end
2019-12-04 20:38:33 +05:30
Issuable::CommonSystemNotesService.prepend_if_ee('EE::Issuable::CommonSystemNotesService')