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

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

113 lines
3.6 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
2021-06-08 01:23:25 +05:30
class CommonSystemNotesService < ::BaseProjectService
2018-03-17 18:26:18 +05:30
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
2021-10-27 15:23:28 +05:30
ApplicationRecord.no_touching do
2020-01-01 13:55:28 +05:30
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-11-24 15:15:51 +05:30
create_milestone_change_event(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
2021-01-29 00:20:46 +05:30
def create_draft_note(old_title)
2018-03-17 18:26:18 +05:30
return unless issuable.is_a?(MergeRequest)
2022-07-23 23:45:48 +05:30
if MergeRequest.draft?(old_title) != issuable.draft?
2021-01-29 00:20:46 +05:30
SystemNoteService.handle_merge_request_draft(issuable, issuable.project, current_user)
2018-03-17 18:26:18 +05:30
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)
2021-01-29 00:20:46 +05:30
create_draft_note(old_title)
2018-03-17 18:26:18 +05:30
2022-04-04 11:22:00 +05:30
if issuable.draftless_title_changed(old_title)
2018-03-17 18:26:18 +05:30
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_change_event(old_milestone)
ResourceEvents::ChangeMilestoneService.new(issuable, current_user, old_milestone: old_milestone)
.execute
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
2021-06-08 01:23:25 +05:30
Issuable::CommonSystemNotesService.prepend_mod_with('Issuable::CommonSystemNotesService')