2018-09-07 09:39:20 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2020-01-02 08:03:23 -05:00
|
|
|
# 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-09-07 09:39:20 -04:00
|
|
|
|
|
|
|
module ResourceEvents
|
|
|
|
class MergeIntoNotesService
|
|
|
|
include Gitlab::Utils::StrongMemoize
|
|
|
|
|
2020-02-19 13:09:10 -05:00
|
|
|
SYNTHETIC_NOTE_BUILDER_SERVICES = [
|
|
|
|
SyntheticLabelNotesBuilderService,
|
2020-05-22 08:08:15 -04:00
|
|
|
SyntheticMilestoneNotesBuilderService,
|
|
|
|
SyntheticStateNotesBuilderService
|
2020-02-19 13:09:10 -05:00
|
|
|
].freeze
|
|
|
|
|
2018-09-07 09:39:20 -04:00
|
|
|
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-05-22 08:08:15 -04:00
|
|
|
(notes + synthetic_notes).sort_by(&:created_at)
|
2018-09-07 09:39:20 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
2020-01-02 08:03:23 -05:00
|
|
|
def synthetic_notes
|
2020-02-19 13:09:10 -05:00
|
|
|
SYNTHETIC_NOTE_BUILDER_SERVICES.flat_map do |service|
|
|
|
|
service.new(resource, current_user, params).execute
|
|
|
|
end
|
2018-09-07 09:39:20 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2020-01-02 08:03:23 -05:00
|
|
|
|
2021-05-11 17:10:21 -04:00
|
|
|
ResourceEvents::MergeIntoNotesService.prepend_mod_with('ResourceEvents::MergeIntoNotesService')
|