From 8cc74e37366b2182fc46ec50b49879a33cbc3dc3 Mon Sep 17 00:00:00 2001 From: htnosm Date: Fri, 1 Oct 2021 07:35:50 +0900 Subject: [PATCH] Add use_raw_output to slack --- README.md | 16 ++++++++++++++++ main.go | 17 +++++++++-------- notifier/slack/client.go | 17 +++++++++-------- notifier/slack/notify.go | 9 +++++---- 4 files changed, 39 insertions(+), 20 deletions(-) diff --git a/README.md b/README.md index 0957dfd..0cdbf3d 100644 --- a/README.md +++ b/README.md @@ -338,6 +338,22 @@ terraform: ``` ``` +Sometimes you may want not to HTML-escape Terraform command outputs. +For example, when you use code block to print command output, it's better to use raw characters instead of character references (e.g. `-/+` -> `-/+`, `"` -> `"`). + +You can disable HTML escape by adding `use_raw_output: true` configuration. +With this configuration, Terraform doesn't HTML-escape any Terraform output. + +~~~yaml +--- +# ... +terraform: + use_raw_output: true + # ... + plan: + # ... +~~~ +
diff --git a/main.go b/main.go index 505c9d7..6f97501 100644 --- a/main.go +++ b/main.go @@ -153,14 +153,15 @@ func (t *tfnotify) Run() error { notifier = client.Notify case "slack": client, err := slack.NewClient(slack.Config{ - Token: t.config.Notifier.Slack.Token, - Channel: t.config.Notifier.Slack.Channel, - Botname: t.config.Notifier.Slack.Bot, - Title: t.context.String("title"), - Message: t.context.String("message"), - CI: ci.URL, - Parser: t.parser, - Template: t.template, + Token: t.config.Notifier.Slack.Token, + Channel: t.config.Notifier.Slack.Channel, + Botname: t.config.Notifier.Slack.Bot, + Title: t.context.String("title"), + Message: t.context.String("message"), + CI: ci.URL, + Parser: t.parser, + UseRawOutput: t.config.Terraform.UseRawOutput, + Template: t.template, }) if err != nil { return err diff --git a/notifier/slack/client.go b/notifier/slack/client.go index 5b8104a..4678b42 100644 --- a/notifier/slack/client.go +++ b/notifier/slack/client.go @@ -33,14 +33,15 @@ type Client struct { // Config is a configuration for Slack client type Config struct { - Token string - Channel string - Botname string - Title string - Message string - CI string - Parser terraform.Parser - Template terraform.Template + Token string + Channel string + Botname string + Title string + Message string + CI string + Parser terraform.Parser + UseRawOutput bool + Template terraform.Template } type service struct { diff --git a/notifier/slack/notify.go b/notifier/slack/notify.go index fe44b3a..c4348e2 100644 --- a/notifier/slack/notify.go +++ b/notifier/slack/notify.go @@ -39,10 +39,11 @@ func (s *NotifyService) Notify(body string) (exit int, err error) { } template.SetValue(terraform.CommonTemplate{ - Title: cfg.Title, - Message: cfg.Message, - Result: result.Result, - Body: body, + Title: cfg.Title, + Message: cfg.Message, + Result: result.Result, + Body: body, + UseRawOutput: cfg.UseRawOutput, }) text, err := template.Execute() if err != nil {