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

125 lines
4 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
2020-05-24 23:13:21 +05:30
def execute(issuable, old_labels: [], old_milestone: nil, 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-05-24 23:13:21 +05:30
create_milestone_note(old_milestone) if issuable.previous_changes.include?('milestone_id')
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
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
2020-05-24 23:13:21 +05:30
def create_milestone_note(old_milestone)
2020-04-08 14:13:33 +05:30
if milestone_changes_tracking_enabled?
2020-05-24 23:13:21 +05:30
create_milestone_change_event(old_milestone)
2020-04-08 14:13:33 +05:30
else
SystemNoteService.change_milestone(issuable, issuable.project, current_user, issuable.milestone)
end
end
2020-05-24 23:13:21 +05:30
def create_milestone_change_event(old_milestone)
ResourceEvents::ChangeMilestoneService.new(issuable, current_user, old_milestone: old_milestone)
.execute
end
2020-04-08 14:13:33 +05:30
def milestone_changes_tracking_enabled?
2020-10-24 23:57:45 +05:30
::Feature.enabled?(:track_resource_milestone_change_events, issuable.project, default_enabled: true)
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')