diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-12-20 17:22:11 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-12-20 17:22:11 +0300 |
commit | 0c872e02b2c822e3397515ec324051ff540f0cd5 (patch) | |
tree | ce2fb6ce7030e4dad0f4118d21ab6453e5938cdd /lib/pager_duty | |
parent | f7e05a6853b12f02911494c4b3fe53d9540d74fc (diff) |
Add latest changes from gitlab-org/gitlab@15-7-stable-eev15.7.0-rc42
Diffstat (limited to 'lib/pager_duty')
-rw-r--r-- | lib/pager_duty/validator/schemas/message.json | 101 | ||||
-rw-r--r-- | lib/pager_duty/webhook_payload_parser.rb | 36 |
2 files changed, 88 insertions, 49 deletions
diff --git a/lib/pager_duty/validator/schemas/message.json b/lib/pager_duty/validator/schemas/message.json index b1a3185cd1a..eeec6657587 100644 --- a/lib/pager_duty/validator/schemas/message.json +++ b/lib/pager_duty/validator/schemas/message.json @@ -1,44 +1,77 @@ { "type": "object", - "required": ["event", "incident"], + "required": [ + "event" + ], "properties": { - "event": { "type": "string" }, - "incident": { + "event": { "type": "object", "required": [ - "html_url", - "incident_number", - "title", - "status", - "created_at", - "urgency", - "incident_key" - ], - "properties": { - "html_url": { "type": "string" }, - "incindent_number": { "type": "integer" }, - "title": { "type": "string" }, - "status": { "type": "string" }, - "created_at": { "type": "string" }, - "urgency": { "type": "string", "enum": ["high", "low"] }, - "incident_key": { "type": ["string", "null"] }, - "assignments": { - "type": "array", - "items": { - "assignee": { - "type": "array", - "items": { - "summary": { "type": "string" }, - "html_url": { "type": "string" } + "data" + ] + }, + "properties": { + "data": { + "type": "object", + "required": [ + "html_url", + "number", + "title", + "status", + "created_at", + "urgency", + "incident_key" + ], + "properties": { + "html_url": { + "type": "string" + }, + "number": { + "type": "integer" + }, + "title": { + "type": "string" + }, + "status": { + "type": "string" + }, + "created_at": { + "type": "string" + }, + "urgency": { + "type": "string", + "enum": [ + "high", + "low" + ] + }, + "incident_key": { + "type": [ + "string", + "null" + ] + }, + "assignee": { + "type": "array", + "items": { + "summary": { + "type": "string" + }, + "html_url": { + "type": "string" + } + } + }, + "service": { + "type": "object", + "items": { + "summary": { + "type": "string" + }, + "html_url": { + "type": "string" } } - } - }, - "impacted_services": { - "type": "array", - "items": { - "summary": { "type": "string" }, - "html_url": { "type": "string" } } } } diff --git a/lib/pager_duty/webhook_payload_parser.rb b/lib/pager_duty/webhook_payload_parser.rb index c17e3df1a72..e65341232f5 100644 --- a/lib/pager_duty/webhook_payload_parser.rb +++ b/lib/pager_duty/webhook_payload_parser.rb @@ -13,7 +13,7 @@ module PagerDuty end def call - Array(payload['messages']).map { |msg| parse_message(msg) }.reject(&:empty?) + parse_message(payload) end private @@ -24,41 +24,47 @@ module PagerDuty return {} unless valid_message?(message) { - 'event' => message['event'], - 'incident' => parse_incident(message['incident']) + 'event' => message.dig('event', 'event_type'), + 'incident' => parse_incident(message.dig('event', 'data')) } end def parse_incident(incident) + return {} unless incident + { 'url' => incident['html_url'], - 'incident_number' => incident['incident_number'], + 'incident_number' => incident['number'], 'title' => incident['title'], 'status' => incident['status'], 'created_at' => incident['created_at'], 'urgency' => incident['urgency'], 'incident_key' => incident['incident_key'], 'assignees' => reject_empty(parse_assignees(incident)), - 'impacted_services' => reject_empty(parse_impacted_services(incident)) + 'impacted_service' => parse_impacted_service(incident) } end def parse_assignees(incident) - Array(incident['assignments']).map do |a| + return [] unless incident + + Array(incident['assignees']).map do |a| { - 'summary' => a.dig('assignee', 'summary'), - 'url' => a.dig('assignee', 'html_url') + 'summary' => a['summary'], + 'url' => a['html_url'] } end end - def parse_impacted_services(incident) - Array(incident['impacted_services']).map do |is| - { - 'summary' => is['summary'], - 'url' => is['html_url'] - } - end + def parse_impacted_service(incident) + return {} unless incident + + return {} if incident.dig('service', 'summary').blank? && incident.dig('service', 'html_url').blank? + + { + 'summary' => incident.dig('service', 'summary'), + 'url' => incident.dig('service', 'html_url') + } end def reject_empty(entities) |