debian-mirror-gitlab/app/models/state_note.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

48 lines
1.1 KiB
Ruby
Raw Normal View History

2020-05-24 23:13:21 +05:30
# frozen_string_literal: true
class StateNote < SyntheticNote
2020-07-28 23:09:34 +05:30
include Gitlab::Utils::StrongMemoize
2020-05-24 23:13:21 +05:30
def self.from_event(event, resource: nil, resource_parent: nil)
2020-07-28 23:09:34 +05:30
attrs = note_attributes(action_by(event), event, resource, resource_parent)
2020-05-24 23:13:21 +05:30
StateNote.new(attrs)
end
def note_html
2020-07-28 23:09:34 +05:30
@note_html ||= Banzai::Renderer.cacheless_render_field(self, :note, { group: group, project: project })
2020-05-24 23:13:21 +05:30
end
private
def note_text(html: false)
2020-07-28 23:09:34 +05:30
if event.state == 'closed'
if event.close_after_error_tracking_resolve
2022-04-04 11:22:00 +05:30
return 'resolved the corresponding error and closed the issue'
2020-07-28 23:09:34 +05:30
end
if event.close_auto_resolve_prometheus_alert
2022-04-04 11:22:00 +05:30
return 'automatically closed this incident because the alert resolved'
2020-07-28 23:09:34 +05:30
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
2020-05-24 23:13:21 +05:30
end
end