File: state_note.rb

package info (click to toggle)
gitlab 17.6.5-19
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 629,368 kB
  • sloc: ruby: 1,915,304; javascript: 557,307; sql: 60,639; xml: 6,509; sh: 4,567; makefile: 1,239; python: 406
file content (51 lines) | stat: -rw-r--r-- 1,302 bytes parent folder | download
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

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

  self.allow_legacy_sti_class = true

  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

    return "merged manually" if event.state == 'merged' && event_source.is_a?(Commit)

    body = event.state.dup
    body << " with #{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