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
|
|
|
|
return 'resolved the corresponding error and closed the issue.'
|
|
|
|
end
|
|
|
|
|
|
|
|
if event.close_auto_resolve_prometheus_alert
|
|
|
|
return 'automatically closed this issue 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
|
2020-05-24 23:13:21 +05:30
|
|
|
end
|
|
|
|
end
|