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

state_note.rb « models « app - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 93c025a9bf0f48610f16b50b1ef07688e63acb7a (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
# frozen_string_literal: true

class StateNote < SyntheticNote
  include Gitlab::Utils::StrongMemoize

  def self.from_event(event, resource: nil, resource_parent: nil)
    attrs = note_attributes(action_by(event), event, resource, resource_parent)

    StateNote.new(attrs)
  end

  def note_html
    @note_html ||= Banzai::Renderer.cacheless_render_field(self, :note, { group: group, project: project })
  end

  private

  def note_text(html: false)
    if event.state == 'closed'
      if event.close_after_error_tracking_resolve
        return 'resolved the corresponding error and closed the issue'
      end

      if event.close_auto_resolve_prometheus_alert
        return 'automatically closed this incident because the alert resolved'
      end
    end

    body = event.state.dup
    body << " via #{event_source.gfm_reference(project)}" if event_source
    body
  end

  def event_source
    strong_memoize(:event_source) do
      if event.source_commit
        project&.commit(event.source_commit)
      else
        event.source_merge_request
      end
    end
  end

  def self.action_by(event)
    event.state == 'reopened' ? 'opened' : event.state
  end
end