Commit bd0b294f authored by syasonik's avatar syasonik

Move parsing to alert

parent b0e8eb82
...@@ -42,10 +42,6 @@ module Projects ...@@ -42,10 +42,6 @@ module Projects
MARKDOWN MARKDOWN
end end
def alert_markdown
annotations.find { |annotation| annotation.label == 'gitlab_incident_markdown' }&.value
end
private private
def alert_title def alert_title
......
...@@ -49,6 +49,12 @@ module Gitlab ...@@ -49,6 +49,12 @@ module Gitlab
end end
end end
def alert_markdown
strong_memoize(:alert_markdown) do
parse_alert_markdown_from_payload
end
end
def valid? def valid?
project && title && starts_at project && title && starts_at
end end
...@@ -105,6 +111,10 @@ module Gitlab ...@@ -105,6 +111,10 @@ module Gitlab
Rack::Utils.parse_query(uri.query).fetch('g0.expr') Rack::Utils.parse_query(uri.query).fetch('g0.expr')
rescue URI::InvalidURIError, KeyError rescue URI::InvalidURIError, KeyError
end end
def parse_alert_markdown_from_payload
payload&.dig('annotations', 'gitlab_incident_markdown')
end
end end
end end
end end
...@@ -189,6 +189,12 @@ describe Gitlab::Alerting::Alert do ...@@ -189,6 +189,12 @@ describe Gitlab::Alerting::Alert do
end end
end end
describe '#alert_markdown' do
subject { alert.alert_markdown }
it_behaves_like 'parse payload', 'annotations/gitlab_incident_markdown'
end
describe '#valid?' do describe '#valid?' do
before do before do
payload.update( payload.update(
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment