diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-10-05 16:54:15 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-10-05 16:54:15 +0300 |
commit | be834a25982746ffd85252ff502df42bb88cb9d5 (patch) | |
tree | b4d6a8ba0931e12fac08f05abea33a3b8ec2c8a2 /lib/pager_duty/webhook_payload_parser.rb | |
parent | ee925a3597f27e92f83a50937a64068109675b3d (diff) |
Add latest changes from gitlab-org/gitlab@13-5-stable-eev13.5.0-rc32
Diffstat (limited to 'lib/pager_duty/webhook_payload_parser.rb')
-rw-r--r-- | lib/pager_duty/webhook_payload_parser.rb | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/lib/pager_duty/webhook_payload_parser.rb b/lib/pager_duty/webhook_payload_parser.rb index 573fb36f0ca..11071926cf2 100644 --- a/lib/pager_duty/webhook_payload_parser.rb +++ b/lib/pager_duty/webhook_payload_parser.rb @@ -2,6 +2,8 @@ module PagerDuty class WebhookPayloadParser + SCHEMA_PATH = File.join('lib', 'pager_duty', 'validator', 'schemas', 'message.json') + def initialize(payload) @payload = payload end @@ -11,7 +13,7 @@ module PagerDuty end def call - Array(payload['messages']).map { |msg| parse_message(msg) } + Array(payload['messages']).map { |msg| parse_message(msg) }.reject(&:empty?) end private @@ -19,6 +21,8 @@ module PagerDuty attr_reader :payload def parse_message(message) + return {} unless valid_message?(message) + { 'event' => message['event'], 'incident' => parse_incident(message['incident']) @@ -26,8 +30,6 @@ module PagerDuty end def parse_incident(incident) - return {} if incident.blank? - { 'url' => incident['html_url'], 'incident_number' => incident['incident_number'], @@ -62,5 +64,9 @@ module PagerDuty def reject_empty(entities) Array(entities).reject { |e| e['summary'].blank? && e['url'].blank? } end + + def valid_message?(message) + ::JSONSchemer.schema(Pathname.new(SCHEMA_PATH)).valid?(message) + end end end |