Skip to content

Commit

Permalink
Add use_raw_output to slack
Browse files Browse the repository at this point in the history
  • Loading branch information
htnosm committed Sep 30, 2021
1 parent 807b0b1 commit 8cc74e3
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 20 deletions.
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
# ...
~~~

</details>

<details>
Expand Down
17 changes: 9 additions & 8 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
17 changes: 9 additions & 8 deletions notifier/slack/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
9 changes: 5 additions & 4 deletions notifier/slack/notify.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 8cc74e3

Please sign in to comment.