forked from box/mojito
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
I18N-132 - Mojito CLI failures should trigger an incident
An incident is triggered when a Mojito CLI command fails
- Loading branch information
Showing
13 changed files
with
274 additions
and
98 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 0 additions & 53 deletions
53
...ain/java/com/box/l10n/mojito/cli/command/extraction/ExtractionDiffNotificationSender.java
This file was deleted.
Oops, something went wrong.
11 changes: 0 additions & 11 deletions
11
...com/box/l10n/mojito/cli/command/extraction/ExtractionDiffNotificationSenderException.java
This file was deleted.
Oops, something went wrong.
41 changes: 41 additions & 0 deletions
41
cli/src/main/java/com/box/l10n/mojito/cli/command/utils/SlackNotificationSender.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package com.box.l10n.mojito.cli.command.utils; | ||
|
||
import static com.box.l10n.mojito.slack.SlackClient.COLOR_WARNING; | ||
import static com.box.l10n.mojito.slack.request.Attachment.MRKDWNIN_TEXT; | ||
|
||
import com.box.l10n.mojito.slack.SlackClient; | ||
import com.box.l10n.mojito.slack.SlackClientException; | ||
import com.box.l10n.mojito.slack.request.Attachment; | ||
import com.box.l10n.mojito.slack.request.Message; | ||
import com.google.common.base.Strings; | ||
|
||
public class SlackNotificationSender { | ||
private final SlackClient slackClient; | ||
|
||
public SlackNotificationSender(SlackClient slackClient) { | ||
this.slackClient = slackClient; | ||
} | ||
|
||
public void sendMessage(String channel, String message) { | ||
if (!Strings.isNullOrEmpty(message)) { | ||
try { | ||
Message slackMessage = new Message(); | ||
if (Strings.isNullOrEmpty(channel)) { | ||
throw new SlackNotificationSenderException( | ||
"Channel cannot be empty for a Slack notification"); | ||
} | ||
slackMessage.setChannel(channel); | ||
Attachment attachment = new Attachment(); | ||
attachment.setText(message); | ||
attachment.setColor(COLOR_WARNING); | ||
attachment.getMrkdwnIn().add(MRKDWNIN_TEXT); | ||
slackMessage.getAttachments().add(attachment); | ||
|
||
this.slackClient.sendInstantMessage(slackMessage); | ||
} catch (SlackClientException e) { | ||
throw new SlackNotificationSenderException( | ||
"Error sending Slack notification: " + e.getMessage(), e); | ||
} | ||
} | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
...src/main/java/com/box/l10n/mojito/cli/command/utils/SlackNotificationSenderException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package com.box.l10n.mojito.cli.command.utils; | ||
|
||
public class SlackNotificationSenderException extends RuntimeException { | ||
public SlackNotificationSenderException(String message) { | ||
super(message); | ||
} | ||
|
||
public SlackNotificationSenderException(String message, Throwable t) { | ||
super(message, t); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.