From d175913ababfff149a437b32cb087025dfbdd13c Mon Sep 17 00:00:00 2001 From: Chris Berry Date: Tue, 14 May 2019 22:53:50 -0500 Subject: [PATCH] chore(hipchat): remove Hipchat integration (#533) --- README.md | 3 +- .../spinnaker/echo/api/Notification.groovy | 1 - .../echo/config/HipchatConfig.groovy | 63 ---------- .../echo/hipchat/HipchatMessage.groovy | 27 ---- .../hipchat/HipchatNotificationService.groovy | 59 --------- .../echo/hipchat/HipchatService.groovy | 32 ----- .../HipchatNotificationAgent.groovy | 117 ------------------ .../NotificationServiceSpec.groovy | 27 ---- 8 files changed, 2 insertions(+), 327 deletions(-) delete mode 100644 echo-notifications/src/main/groovy/com/netflix/spinnaker/echo/config/HipchatConfig.groovy delete mode 100644 echo-notifications/src/main/groovy/com/netflix/spinnaker/echo/hipchat/HipchatMessage.groovy delete mode 100644 echo-notifications/src/main/groovy/com/netflix/spinnaker/echo/hipchat/HipchatNotificationService.groovy delete mode 100644 echo-notifications/src/main/groovy/com/netflix/spinnaker/echo/hipchat/HipchatService.groovy delete mode 100644 echo-notifications/src/main/groovy/com/netflix/spinnaker/echo/notification/HipchatNotificationAgent.groovy diff --git a/README.md b/README.md index 8a4318c62..ee452719d 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,8 @@ It provides integrations for outgoing notifications in the echo-notifications pa * email * Slack -* Hipchat +* Bearychat +* Google Chat * sms ( via Twilio ) Echo is also able to send events within Spinnaker to a predefined url, which is configurable under the echo-rest module. diff --git a/echo-notifications/src/main/groovy/com/netflix/spinnaker/echo/api/Notification.groovy b/echo-notifications/src/main/groovy/com/netflix/spinnaker/echo/api/Notification.groovy index 79b2ad8b9..0b5a39cfc 100644 --- a/echo-notifications/src/main/groovy/com/netflix/spinnaker/echo/api/Notification.groovy +++ b/echo-notifications/src/main/groovy/com/netflix/spinnaker/echo/api/Notification.groovy @@ -38,7 +38,6 @@ class Notification { EMAIL, GITHUB_STATUS, GOOGLECHAT, - HIPCHAT, JIRA, PAGER_DUTY, PUBSUB, diff --git a/echo-notifications/src/main/groovy/com/netflix/spinnaker/echo/config/HipchatConfig.groovy b/echo-notifications/src/main/groovy/com/netflix/spinnaker/echo/config/HipchatConfig.groovy deleted file mode 100644 index 6f4bfaa01..000000000 --- a/echo-notifications/src/main/groovy/com/netflix/spinnaker/echo/config/HipchatConfig.groovy +++ /dev/null @@ -1,63 +0,0 @@ -/* - * Copyright 2015 Netflix, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - - -package com.netflix.spinnaker.echo.config - -import retrofit.converter.JacksonConverter - -import static retrofit.Endpoints.newFixedEndpoint - -import com.netflix.spinnaker.echo.hipchat.HipchatService -import com.netflix.spinnaker.retrofit.Slf4jRetrofitLogger -import groovy.transform.CompileStatic -import groovy.util.logging.Slf4j -import org.springframework.beans.factory.annotation.Value -import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty -import org.springframework.context.annotation.Bean -import org.springframework.context.annotation.Configuration -import retrofit.Endpoint -import retrofit.RestAdapter -import retrofit.client.Client - -@Configuration -@ConditionalOnProperty('hipchat.enabled') -@Slf4j -@CompileStatic -class HipchatConfig { - - @Bean - Endpoint hipchatEndpoint(@Value('${hipchat.base-url}') String hipchatBaseUrl) { - newFixedEndpoint(hipchatBaseUrl) - } - - @Bean - HipchatService hipchatService(Endpoint hipchatEndpoint, Client retrofitClient, RestAdapter.LogLevel retrofitLogLevel) { - - log.info('hipchat service loaded') - - new RestAdapter.Builder() - .setEndpoint(hipchatEndpoint) - .setConverter(new JacksonConverter()) - .setClient(retrofitClient) - .setLogLevel(retrofitLogLevel) - .setLog(new Slf4jRetrofitLogger(HipchatService.class)) - .build() - .create(HipchatService.class) - } - -} diff --git a/echo-notifications/src/main/groovy/com/netflix/spinnaker/echo/hipchat/HipchatMessage.groovy b/echo-notifications/src/main/groovy/com/netflix/spinnaker/echo/hipchat/HipchatMessage.groovy deleted file mode 100644 index 2dc8a6e14..000000000 --- a/echo-notifications/src/main/groovy/com/netflix/spinnaker/echo/hipchat/HipchatMessage.groovy +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Copyright 2015 Netflix, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - - -package com.netflix.spinnaker.echo.hipchat - -class HipchatMessage { - - String message - String color - Boolean notify - -} diff --git a/echo-notifications/src/main/groovy/com/netflix/spinnaker/echo/hipchat/HipchatNotificationService.groovy b/echo-notifications/src/main/groovy/com/netflix/spinnaker/echo/hipchat/HipchatNotificationService.groovy deleted file mode 100644 index b04dc53c3..000000000 --- a/echo-notifications/src/main/groovy/com/netflix/spinnaker/echo/hipchat/HipchatNotificationService.groovy +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Copyright 2015 Netflix, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.netflix.spinnaker.echo.hipchat - -import com.netflix.spinnaker.echo.controller.EchoResponse -import com.netflix.spinnaker.echo.notification.NotificationService -import com.netflix.spinnaker.echo.api.Notification -import com.netflix.spinnaker.echo.notification.NotificationTemplateEngine -import org.springframework.beans.factory.annotation.Autowired -import org.springframework.beans.factory.annotation.Value -import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty -import org.springframework.stereotype.Component - -@Component -@ConditionalOnProperty('hipchat.enabled') -class HipchatNotificationService implements NotificationService { - private static Notification.Type TYPE = Notification.Type.HIPCHAT - - @Autowired - HipchatService hipchat - - @Autowired - NotificationTemplateEngine notificationTemplateEngine - - @Value('${hipchat.token}') - String token - - @Override - boolean supportsType(Notification.Type type) { - return type == TYPE - } - - @Override - EchoResponse.Void handle(Notification notification) { - def body = notificationTemplateEngine.build(notification, NotificationTemplateEngine.Type.BODY) - notification.to.each { - hipchat.sendMessage(token, it, new HipchatMessage( - message: body, - notify: notification.severity == Notification.Severity.HIGH - )) - } - - new EchoResponse.Void() - } -} diff --git a/echo-notifications/src/main/groovy/com/netflix/spinnaker/echo/hipchat/HipchatService.groovy b/echo-notifications/src/main/groovy/com/netflix/spinnaker/echo/hipchat/HipchatService.groovy deleted file mode 100644 index 39000bcf2..000000000 --- a/echo-notifications/src/main/groovy/com/netflix/spinnaker/echo/hipchat/HipchatService.groovy +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright 2015 Netflix, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - - -package com.netflix.spinnaker.echo.hipchat - -import retrofit.client.Response -import retrofit.http.Body -import retrofit.http.POST -import retrofit.http.Path -import retrofit.http.Query - -interface HipchatService { - - @POST("/v2/room/{room}/notification") - Response sendMessage(@Query("auth_token") String token, @Path("room") String room, @Body HipchatMessage message) - -} 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 deleted file mode 100644 index bef199c8e..000000000 --- a/echo-notifications/src/main/groovy/com/netflix/spinnaker/echo/notification/HipchatNotificationAgent.groovy +++ /dev/null @@ -1,117 +0,0 @@ -/* - * Copyright 2015 Netflix, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.netflix.spinnaker.echo.notification - -import com.netflix.spinnaker.echo.hipchat.HipchatMessage -import com.netflix.spinnaker.echo.hipchat.HipchatService -import com.netflix.spinnaker.echo.model.Event -import groovy.util.logging.Slf4j -import org.apache.commons.lang.WordUtils -import org.springframework.beans.factory.annotation.Autowired -import org.springframework.beans.factory.annotation.Value -import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty -import org.springframework.stereotype.Service - -import static net.logstash.logback.argument.StructuredArguments.kv - -@Slf4j -@ConditionalOnProperty('hipchat.enabled') -@Service -class HipchatNotificationAgent extends AbstractEventNotificationAgent { - - @Autowired - HipchatService hipchatService - - @Value('${hipchat.token}') - String token - - @Override - void sendNotifications(Map preference, String application, Event event, Map config, String status) { - try { - boolean notify = false - if (status == 'failed') { - notify = true - } - - String color = 'gray' - - if (status == 'failed') { - color = 'red' - } - - if (status == 'complete') { - color = 'green' - } - - String buildInfo = '' - - if (config.type == 'pipeline' || config.type == 'stage') { - if (event.content?.execution?.trigger?.buildInfo?.url) { - buildInfo = """build #${ - event.content.execution.trigger.buildInfo.number as Integer - } """ - } - } - - log.info('Sending Hipchat message {} for {} {} {} {}', kv('address', preference.address), kv('application', application), kv('type', config.type), kv('status', status), kv('executionId', event.content?.execution?.id)) - - - String message = '' - - if (config.type == 'stage') { - 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}" - - message += - """${WordUtils.capitalize(application)}'s ${ - event.content?.execution?.name ?: event.content?.execution?.description - } ${buildInfo} ${config.type == 'task' ? 'task' : 'pipeline'} ${status == 'starting' ? 'is' : 'has'} ${ - status == 'complete' ? 'completed successfully' : status - }""" - - String customMessage = event.content?.context?.customMessage - if (customMessage) { - message = customMessage - .replace("{{executionId}}", (String) event.content.execution?.id ?: "") - .replace("{{link}}", link ?: "") - } - - hipchatService.sendMessage( - token, - preference.address, - new HipchatMessage( - message: message, - color: color, - notify: notify - ) - ) - - } catch (Exception e) { - log.error('failed to send hipchat message ', e) - } - } - - @Override - String getNotificationType() { - 'hipchat' - } - -} - diff --git a/echo-notifications/src/test/groovy/com/netflix/spinnaker/echo/notification/NotificationServiceSpec.groovy b/echo-notifications/src/test/groovy/com/netflix/spinnaker/echo/notification/NotificationServiceSpec.groovy index fee47e080..792d5e359 100644 --- a/echo-notifications/src/test/groovy/com/netflix/spinnaker/echo/notification/NotificationServiceSpec.groovy +++ b/echo-notifications/src/test/groovy/com/netflix/spinnaker/echo/notification/NotificationServiceSpec.groovy @@ -17,9 +17,6 @@ package com.netflix.spinnaker.echo.notification import com.netflix.spinnaker.echo.api.Notification -import com.netflix.spinnaker.echo.hipchat.HipchatMessage -import com.netflix.spinnaker.echo.hipchat.HipchatNotificationService -import com.netflix.spinnaker.echo.hipchat.HipchatService import com.netflix.spinnaker.echo.twilio.TwilioNotificationService import com.netflix.spinnaker.echo.twilio.TwilioService import org.springframework.boot.autoconfigure.freemarker.FreeMarkerNonWebConfiguration @@ -42,30 +39,6 @@ class NotificationServiceSpec extends Specification { ) } - void "should send specific hipchat message"() { - given: - def hipchatService = Mock(HipchatService) - def hipchatNotificationService = new HipchatNotificationService( - token: "token", - notificationTemplateEngine: notificationTemplateEngine, - hipchat: hipchatService - ) - def notification = new Notification( - notificationType: "HIPCHAT", - templateGroup: "example", - to: ["room"], - source: new Notification.Source(application: "application") - ) - - when: - hipchatNotificationService.handle(notification) - - then: - 1 * hipchatService.sendMessage("token", "room", { HipchatMessage message -> - message.message == "specific SPINNAKER_URL application" - } as HipchatMessage) - } - void "should send generic twilio message"() { given: def twilioService = Mock(TwilioService)