Commit 33b5f0c4 authored by Peter Leitzen's avatar Peter Leitzen

Make NotifyService more robust

Be resilient if `alerts` are missing in the payload.
parent 1486304d
......@@ -63,7 +63,7 @@ module Projects
end
def gitlab_alert_id
alerts.first.dig('labels', 'gitlab_alert_id')
alerts&.first&.dig('labels', 'gitlab_alert_id')
end
def compare_token(expected, actual)
......
......@@ -158,6 +158,12 @@ describe Projects::Prometheus::Alerts::NotifyService do
it_behaves_like 'no notifications'
end
context 'with missing alerts' do
let(:payload) { { 'version' => '4' } }
it_behaves_like 'no notifications'
end
end
private
......
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