Skip to content

Commit

Permalink
Merge pull request #47 from myokoo/add-override-itemes
Browse files Browse the repository at this point in the history
add override itemes on slack
  • Loading branch information
sawanoboly authored Mar 15, 2019
2 parents 84b7c2a + 4818d2d commit 7ee418a
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,34 @@ public class SlackNotificationPlugin implements NotificationPlugin {
private String webhook_url_override;

@PluginProperty(
title = "Notification template",
description = "Custom notification template, if not supplied the defaults will be used",
scope = PropertyScope.InstanceOnly,
required = false
title = "Notification channel Override",
description = "Notification channel",
scope = PropertyScope.InstanceOnly,
required = false
)
private String slack_channel_override;

@PluginProperty(
title = "Notification username Override",
description = "Notification username",
scope = PropertyScope.InstanceOnly,
required = false
)
private String slack_username_override;

@PluginProperty(
title = "Notification icon Override",
description = "Notification icon",
scope = PropertyScope.InstanceOnly,
required = false
)
private String slack_icon_override;

@PluginProperty(
title = "Notification template",
description = "Custom notification template, if not supplied the defaults will be used",
scope = PropertyScope.InstanceOnly,
required = false
)
private String slack_template;

Expand Down Expand Up @@ -222,6 +246,10 @@ private String generateMessage(final String trigger, final Map executionData, fi
model.put("color", color);
model.put("executionData", executionData);
model.put("config", config);
model.put("channel_override", this.slack_channel_override);
model.put("username_override", this.slack_username_override);
model.put("icon_override", this.slack_icon_override);

final StringWriter writer = new StringWriter();
try {
Template ftl = SlackNotificationPlugin.FREEMARKER_CFG.getTemplate(template);
Expand Down
9 changes: 9 additions & 0 deletions src/main/resources/templates/slack-template-error.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,15 @@
</#if>

{
<#if channel_override?has_content >
"channel":"${channel_override}",
</#if>
<#if username_override?has_content >
"username": "${username_override}",
</#if>
<#if icon_override?has_content >
"icon_emoji":"${icon_override}",
</#if>
"attachments":[
{
"fallback":"${state}: ${message}",
Expand Down
9 changes: 9 additions & 0 deletions src/main/resources/templates/slack-template-started.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,15 @@
<#assign state="Started">

{
<#if channel_override?has_content >
"channel":"${channel_override}",
</#if>
<#if username_override?has_content >
"username": "${username_override}",
</#if>
<#if icon_override?has_content >
"icon_emoji":"${icon_override}",
</#if>
"attachments":[
{
"fallback":"${state}: ${message}",
Expand Down
9 changes: 9 additions & 0 deletions src/main/resources/templates/slack-template-success.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,15 @@
<#assign state="Succeeded">

{
<#if channel_override?has_content >
"channel":"${channel_override}",
</#if>
<#if username_override?has_content >
"username": "${username_override}",
</#if>
<#if icon_override?has_content >
"icon_emoji":"${icon_override}",
</#if>
"attachments":[
{
"fallback":"${state}: ${message}",
Expand Down

0 comments on commit 7ee418a

Please sign in to comment.