2018-11-20 20:47:30 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2020-03-13 15:44:24 +05:30
|
|
|
# We store events about issuable label changes and weight changes in separate tables (not as
|
|
|
|
# other system notes), but we still want to display notes about label and weight changes
|
|
|
|
# as classic system notes in UI. This service merges synthetic label and weight notes
|
|
|
|
# with classic notes and sorts them by creation time.
|
2018-11-20 20:47:30 +05:30
|
|
|
|
|
|
|
module ResourceEvents
|
|
|
|
class MergeIntoNotesService
|
|
|
|
include Gitlab::Utils::StrongMemoize
|
|
|
|
|
2020-04-08 14:13:33 +05:30
|
|
|
SYNTHETIC_NOTE_BUILDER_SERVICES = [
|
|
|
|
SyntheticLabelNotesBuilderService,
|
2020-06-23 00:09:42 +05:30
|
|
|
SyntheticMilestoneNotesBuilderService,
|
|
|
|
SyntheticStateNotesBuilderService
|
2020-04-08 14:13:33 +05:30
|
|
|
].freeze
|
|
|
|
|
2018-11-20 20:47:30 +05:30
|
|
|
attr_reader :resource, :current_user, :params
|
|
|
|
|
|
|
|
def initialize(resource, current_user, params = {})
|
|
|
|
@resource = resource
|
|
|
|
@current_user = current_user
|
|
|
|
@params = params
|
|
|
|
end
|
|
|
|
|
|
|
|
def execute(notes = [])
|
2020-06-23 00:09:42 +05:30
|
|
|
(notes + synthetic_notes).sort_by(&:created_at)
|
2018-11-20 20:47:30 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
2020-03-13 15:44:24 +05:30
|
|
|
def synthetic_notes
|
2020-04-08 14:13:33 +05:30
|
|
|
SYNTHETIC_NOTE_BUILDER_SERVICES.flat_map do |service|
|
|
|
|
service.new(resource, current_user, params).execute
|
|
|
|
end
|
2018-11-20 20:47:30 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2020-03-13 15:44:24 +05:30
|
|
|
|
2021-06-08 01:23:25 +05:30
|
|
|
ResourceEvents::MergeIntoNotesService.prepend_mod_with('ResourceEvents::MergeIntoNotesService')
|