Skip to content

Commit

Permalink
Merge pull request #99 from htnosm/add-raw-output-to-slack
Browse files Browse the repository at this point in the history
Add use_raw_output option to slack
  • Loading branch information
drlau authored Dec 14, 2022
2 parents e60974f + ab7648b commit ddb68ef
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 21 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
11 changes: 6 additions & 5 deletions notifier/slack/notify.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,12 @@ 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,
Link: cfg.CI,
Title: cfg.Title,
Message: cfg.Message,
Result: result.Result,
Body: body,
UseRawOutput: cfg.UseRawOutput,
Link: cfg.CI,
})
text, err := template.Execute()
if err != nil {
Expand Down

0 comments on commit ddb68ef

Please sign in to comment.