Skip to content

Commit

Permalink
fix(notification): Support channel ID as Slack notification address (#…
Browse files Browse the repository at this point in the history
…932)

Co-authored-by: Qijia Wang <qijia.wang@grabtaxi.com>
  • Loading branch information
gomid and Qijia Wang committed Jun 17, 2020
1 parent 3fcfea9 commit ead9b91
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ class SlackNotificationAgent extends AbstractEventNotificationAgent {
.replace("{{link}}", link ?: "")
}

String address = preference.address.startsWith('#') ? preference.address : "#${preference.address}"
String address = preference.address

Response response
if (sendCompactMessages) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class SlackNotificationService implements NotificationService {
def text = notificationTemplateEngine.build(notification, NotificationTemplateEngine.Type.BODY)
notification.to.each {
def response
String address = it.startsWith('#') ? it : "#${it}"
String address = it
if (slack.config.sendCompactMessages) {
response = slack.sendCompactMessage(new CompactSlackMessage(text), address, true)
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class SlackNotificationServiceSpec extends Specification {
given:
Notification notification = new Notification()
notification.notificationType = "SLACK"
notification.to = [ "channel1", "channel2" ]
notification.to = [ "channel1", "#channel2", "C12345678" ]
notification.severity = Notification.Severity.NORMAL
notification.additionalContext["body"] = "text"

Expand All @@ -54,6 +54,8 @@ class SlackNotificationServiceSpec extends Specification {
service.handle(notification)

then:
notification.to.size() * slack.sendMessage(*_)
1 * slack.sendMessage(_, "channel1", _)
1 * slack.sendMessage(_, "#channel2", _)
1 * slack.sendMessage(_, "C12345678", _)
}
}

0 comments on commit ead9b91

Please sign in to comment.