From be7fd9eeb33474c071d7bf84d602757e15b29ee5 Mon Sep 17 00:00:00 2001 From: Lars Wander Date: Tue, 20 Feb 2018 12:47:20 -0500 Subject: [PATCH] fix(stage notifications): consuming updated orca payload (#238) (#239) --- .../AbstractEventNotificationAgent.groovy | 3 ++- .../echo/notification/EmailNotificationAgent.groovy | 3 ++- .../echo/notification/HipchatNotificationAgent.groovy | 3 ++- .../echo/notification/SlackNotificationAgent.groovy | 3 ++- .../echo/notification/TwilioNotificationAgent.groovy | 3 ++- .../notification/EmailNotificationAgentSpec.groovy | 11 +++++++---- .../notification/SlackNotificationAgentSpec.groovy | 7 +++++-- 7 files changed, 22 insertions(+), 11 deletions(-) diff --git a/echo-notifications/src/main/groovy/com/netflix/spinnaker/echo/notification/AbstractEventNotificationAgent.groovy b/echo-notifications/src/main/groovy/com/netflix/spinnaker/echo/notification/AbstractEventNotificationAgent.groovy index 9e0398816..0a1611b63 100644 --- a/echo-notifications/src/main/groovy/com/netflix/spinnaker/echo/notification/AbstractEventNotificationAgent.groovy +++ b/echo-notifications/src/main/groovy/com/netflix/spinnaker/echo/notification/AbstractEventNotificationAgent.groovy @@ -89,7 +89,8 @@ abstract class AbstractEventNotificationAgent implements EchoEventListener { // stage level configurations if (config.type == 'stage') { - if (event.content?.context?.sendNotifications && ( event.content?.context?.stageDetails?.isSynthetic == false ) ) { + boolean isSynthetic = event.content?.isSynthetic?: event.content?.context?.stageDetails?.isSynthetic + if (event.content?.context?.sendNotifications && ( !isSynthetic ) ) { event.content?.context?.notifications?.each { notification -> String key = getNotificationType() if (notification.type == key && notification?.when?.contains("$config.type.$status".toString())) { diff --git a/echo-notifications/src/main/groovy/com/netflix/spinnaker/echo/notification/EmailNotificationAgent.groovy b/echo-notifications/src/main/groovy/com/netflix/spinnaker/echo/notification/EmailNotificationAgent.groovy index 75ee60d15..ad748aa5f 100644 --- a/echo-notifications/src/main/groovy/com/netflix/spinnaker/echo/notification/EmailNotificationAgent.groovy +++ b/echo-notifications/src/main/groovy/com/netflix/spinnaker/echo/notification/EmailNotificationAgent.groovy @@ -59,7 +59,8 @@ class EmailNotificationAgent extends AbstractEventNotificationAgent { String subject if (config.type == 'stage') { - subject = """Stage ${context.stageDetails.name} for ${ + String stageName = event.content.name ?: context.stageDetails.name + subject = """Stage $stageName for ${ application }'s ${event.content?.execution?.name} pipeline ${buildInfo}""" } else if (config.type == 'pipeline') { diff --git a/echo-notifications/src/main/groovy/com/netflix/spinnaker/echo/notification/HipchatNotificationAgent.groovy b/echo-notifications/src/main/groovy/com/netflix/spinnaker/echo/notification/HipchatNotificationAgent.groovy index 888957cdf..bef199c8e 100644 --- a/echo-notifications/src/main/groovy/com/netflix/spinnaker/echo/notification/HipchatNotificationAgent.groovy +++ b/echo-notifications/src/main/groovy/com/netflix/spinnaker/echo/notification/HipchatNotificationAgent.groovy @@ -73,7 +73,8 @@ class HipchatNotificationAgent extends AbstractEventNotificationAgent { String message = '' if (config.type == 'stage') { - message = """Stage ${event.content?.context?.stageDetails.name} for """ + String stageName = event.content.name ?: event.content?.context?.stageDetails?.name + message = """Stage $stageName for """ } String link = "${spinnakerUrl}/#/applications/${application}/${config.type == 'stage' ? 'executions/details' : config.link }/${event.content?.execution?.id}" diff --git a/echo-notifications/src/main/groovy/com/netflix/spinnaker/echo/notification/SlackNotificationAgent.groovy b/echo-notifications/src/main/groovy/com/netflix/spinnaker/echo/notification/SlackNotificationAgent.groovy index e12d6b50c..2e6704f51 100644 --- a/echo-notifications/src/main/groovy/com/netflix/spinnaker/echo/notification/SlackNotificationAgent.groovy +++ b/echo-notifications/src/main/groovy/com/netflix/spinnaker/echo/notification/SlackNotificationAgent.groovy @@ -76,7 +76,8 @@ class SlackNotificationAgent extends AbstractEventNotificationAgent { String body = '' if (config.type == 'stage') { - body = """Stage ${event.content?.context?.stageDetails?.name} for """ + String stageName = event.content.name ?: event.content?.context?.stageDetails?.name + body = """Stage $stageName for """ } String link = "${spinnakerUrl}/#/applications/${application}/${config.type == 'stage' ? 'executions/details' : config.link }/${event.content?.execution?.id}" diff --git a/echo-notifications/src/main/groovy/com/netflix/spinnaker/echo/notification/TwilioNotificationAgent.groovy b/echo-notifications/src/main/groovy/com/netflix/spinnaker/echo/notification/TwilioNotificationAgent.groovy index 0dae30162..78440eee2 100644 --- a/echo-notifications/src/main/groovy/com/netflix/spinnaker/echo/notification/TwilioNotificationAgent.groovy +++ b/echo-notifications/src/main/groovy/com/netflix/spinnaker/echo/notification/TwilioNotificationAgent.groovy @@ -58,7 +58,8 @@ class TwilioNotificationAgent extends AbstractEventNotificationAgent { String message = '' if (config.type == 'stage') { - message = """Stage ${event.content?.context?.stageDetails.name} for """ + String stageName = event.content.name ?: event.content?.context?.stageDetails?.name + message = """Stage $stageName for """ } message += diff --git a/echo-notifications/src/test/groovy/com/netflix/spinnaker/echo/notification/EmailNotificationAgentSpec.groovy b/echo-notifications/src/test/groovy/com/netflix/spinnaker/echo/notification/EmailNotificationAgentSpec.groovy index d520a155e..293120763 100644 --- a/echo-notifications/src/test/groovy/com/netflix/spinnaker/echo/notification/EmailNotificationAgentSpec.groovy +++ b/echo-notifications/src/test/groovy/com/netflix/spinnaker/echo/notification/EmailNotificationAgentSpec.groovy @@ -71,7 +71,10 @@ class EmailNotificationAgentSpec extends Specification { status = "complete" pipelineName = "foo-pipeline" stageName = "foo-stage" - event = new Event(content: [context: [stageDetails: [name: "foo-stage"]], execution: [name: "foo-pipeline"]]) + event = new Event(content: [ + execution: [id: "1", name: "foo-pipeline"], + name: "foo-stage" + ]) } @Unroll @@ -115,7 +118,7 @@ class EmailNotificationAgentSpec extends Specification { address = "whoever@netflix.com" pipelineName = "foo-pipeline" stageName = "foo-stage" - event = new Event(content: [context: [stageDetails: [name: "foo-stage"]], execution: [name: "foo-pipeline"]]) + event = new Event(content: [name: "foo-stage", execution: [name: "foo-pipeline"]]) message = ["complete", "starting", "failed"].collectEntries { [("$type.$it".toString()): [text: "custom $it text"]] } @@ -156,8 +159,8 @@ class EmailNotificationAgentSpec extends Specification { pipelineName = "foo-pipeline" stageName = "foo-stage" event = new Event(content: [context: [customSubject: customSubject, - customBody: customBody, - stageDetails: [name: "foo-stage"]], + customBody: customBody], + name: "foo-stage", execution: [id: "abc", name: "foo-pipeline"]]) } } diff --git a/echo-notifications/src/test/groovy/com/netflix/spinnaker/echo/notification/SlackNotificationAgentSpec.groovy b/echo-notifications/src/test/groovy/com/netflix/spinnaker/echo/notification/SlackNotificationAgentSpec.groovy index 1192d75c7..910828f14 100644 --- a/echo-notifications/src/test/groovy/com/netflix/spinnaker/echo/notification/SlackNotificationAgentSpec.groovy +++ b/echo-notifications/src/test/groovy/com/netflix/spinnaker/echo/notification/SlackNotificationAgentSpec.groovy @@ -107,8 +107,11 @@ class SlackNotificationAgentSpec extends Specification { channel = "bluespar" application = "whatever" - event = new Event(content: [execution: [id: "1", name: "foo-pipeline"], - context: [ customMessage: customMessage, stageDetails: [ name: 'a stage' ]]]) + event = new Event(content: [ + execution: [id: "1", name: "foo-pipeline"], + context: [ customMessage: customMessage ], + name: 'a stage' + ]) type = "stage" } }