Welcome to mirror list, hosted at ThFree Co, Russian Federation.

base_synthetic_notes_builder_service.rb « resource_events « services « app - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 5939b9d2f9c8ff65a1367714e841cfc2a36ec511 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# frozen_string_literal: true

# We store events about issuable label changes and weight changes in a separate
# table (not as other system notes), but we still want to display notes about
# label changes and weight changes as classic system notes in UI.  This service
# generates "synthetic" notes for label event changes.

module ResourceEvents
  class BaseSyntheticNotesBuilderService
    include Gitlab::Utils::StrongMemoize

    attr_reader :resource, :current_user, :params

    def initialize(resource, current_user, params = {})
      @resource = resource
      @current_user = current_user
      @params = params
    end

    def execute
      synthetic_notes
    end

    private

    def apply_common_filters(events)
      events = apply_last_fetched_at(events)
      apply_fetch_until(events)
    end

    def apply_last_fetched_at(events)
      return events unless params[:last_fetched_at].present?

      last_fetched_at = params[:last_fetched_at] - NotesFinder::FETCH_OVERLAP

      events.created_after(last_fetched_at)
    end

    def apply_fetch_until(events)
      return events unless params[:fetch_until].present?

      events.created_on_or_before(params[:fetch_until])
    end

    def resource_parent
      strong_memoize(:resource_parent) do
        resource.project || resource.group
      end
    end
  end
end