Skip to content

Commit

Permalink
Merge pull request #41 from suzuki-shunsuke/fix/remove-title
Browse files Browse the repository at this point in the history
fix: remove title and destroy-warning-title options and template variable ".Title"
  • Loading branch information
suzuki-shunsuke committed Jan 19, 2021
2 parents 516a399 + 4e6afc5 commit 37d7863
Show file tree
Hide file tree
Showing 13 changed files with 98 additions and 140 deletions.
24 changes: 16 additions & 8 deletions COMPARED_WITH_TFNOTIFY.md
Expand Up @@ -8,7 +8,8 @@ tfcmt isn't compatible with tfnotify.
* [Remove `fmt` command](#breaking-change-remove-fmt-command)
* [Configuration file name is changed](#breaking-change-configuration-file-name-is-changed)
* [Command usage is changed](#breaking-change-command-usage-is-changed)
* [Remove --message option and template variable .Message](#breaking-change-remove---message-option-and-template-variable-message)
* [Remove --message and --destroy-warning-message option and template variable .Message](#breaking-change-remove---message-and---destroy-warning-message-option-and-template-variable-message)
* [Remove --title and --destroy-warning-title options and template variable .Title](#breaking-change-remove---title-and---destroy-warning-title-options-and-template-variable-title)
* [Don't remove duplicate comments](#breaking-change-dont-remove-duplicate-comments)
* [Change the behavior of deletion warning](#breaking-change-change-the-behavior-of-deletion-warning)
* Features
Expand Down Expand Up @@ -91,10 +92,19 @@ tfcmt apply -- terraform apply

By this change, tfcmt can handle the standard error output and exit code of the terraform command.

## Breaking Change: Remove --message option and template variable .Message
## Breaking Change: Remove --message and --destroy-warning-message option and template variable .Message

[#40](https://github.com/suzuki-shunsuke/tfcmt/pull/40)

We introduced more general option `-var` and template variable `.Vars`,
so the `--message` and `--destroy-warning-message` options aren't needed.

## Breaking Change: Remove --title and --destroy-warning-title options and template variable .Title

[#41](https://github.com/suzuki-shunsuke/tfcmt/pull/41)

We introduced more general option `-var` and template variable `.Vars`,
so the `--message` option isn't needed.
so the `--title` and `--destroy-warning-title` options aren't needed.

## Breaking Change: Don't remove duplicate comments

Expand All @@ -117,7 +127,7 @@ tfcmt posts only one comment whose template is `when_destroy.template`.
label: "destroy"
label_color: "d93f0b" # red
template: |
{{ .Title }}
## Plan Result
[CI link]( {{ .Link }} )
Expand All @@ -133,8 +143,6 @@ tfcmt posts only one comment whose template is `when_destroy.template`.
</pre></code></details>
```

And the default title of destroy warning is changed to `## :warning: Resource Deletion will happen :warning:`.

### Feature: Add template variables of changed resource paths

[#39](https://github.com/suzuki-shunsuke/tfcmt/pull/39)
Expand Down Expand Up @@ -194,7 +202,7 @@ terraform:
plan:
when_parse_error:
template: |
{{ .Title }} <sup>[CI link]( {{ .Link }} )</sup>
## Plan Result <sup>[CI link]( {{ .Link }} )</sup>
:warning: It failed to parse the result. :warning:
Expand All @@ -205,7 +213,7 @@ terraform:
apply:
when_parse_error:
template: |
{{ .Title }} <sup>[CI link]( {{ .Link }} )</sup>
## Apply Result <sup>[CI link]( {{ .Link }} )</sup>
:warning: It failed to parse the result. :warning:
Expand Down
15 changes: 7 additions & 8 deletions README.md
Expand Up @@ -66,7 +66,6 @@ The example settings of GitHub and GitHub Enterprise are as follows. Incidentall

Placeholder | Usage
---|---
`{{ .Title }}` | Like `## Plan result`
`{{ .Result }}` | Matched result by parsing like `Plan: 1 to add` or `No changes`
`{{ .Body }}` | The entire of Terraform execution result
`{{ .Link }}` | The link of the build page on CI
Expand Down Expand Up @@ -102,7 +101,7 @@ notifier:
terraform:
plan:
template: |
{{ .Title }} <sup>[CI link]( {{ .Link }} )</sup>
## Plan Result <sup>[CI link]( {{ .Link }} )</sup>
{{if .Result}}
<pre><code>{{ .Result }}
</pre></code>
Expand All @@ -113,7 +112,7 @@ terraform:
</pre></code></details>
apply:
template: |
{{ .Title }}
## Apply Result
{{if .Result}}
<pre><code>{{ .Result }}
</pre></code>
Expand All @@ -133,7 +132,7 @@ terraform:
# ...
plan:
template: |
{{ .Title }} <sup>[CI link]( {{ .Link }} )</sup>
## Plan Result <sup>[CI link]( {{ .Link }} )</sup>
{{if .Result}}
<pre><code>{{ .Result }}
</pre></code>
Expand All @@ -159,7 +158,7 @@ terraform:
# ...
plan:
template: |
{{ .Title }} <sup>[CI link]( {{ .Link }} )</sup>
## Plan Result <sup>[CI link]( {{ .Link }} )</sup>
{{if .Result}}
<pre><code>{{ .Result }}
</pre></code>
Expand Down Expand Up @@ -196,7 +195,7 @@ terraform:
# ...
plan:
template: |
{{ .Title }} <sup>[CI link]( {{ .Link }} )</sup>
## Plan Result <sup>[CI link]( {{ .Link }} )</sup>
{{if .Result}}
```
{{ .Result }}
Expand Down Expand Up @@ -228,7 +227,7 @@ notifier:
terraform:
plan:
template: |
{{ .Title }} <sup>[CI link]( {{ .Link }} )</sup>
## Plan Result <sup>[CI link]( {{ .Link }} )</sup>
{{if .Result}}
<pre><code>{{ .Result }}
</pre></code>
Expand All @@ -239,7 +238,7 @@ terraform:
</pre></code></details>
apply:
template: |
{{ .Title }}
## Apply Result
{{if .Result}}
<pre><code>{{ .Result }}
</pre></code>
Expand Down
6 changes: 3 additions & 3 deletions config/config_test.go
Expand Up @@ -40,7 +40,7 @@ func TestLoadFile(t *testing.T) {
Template: "",
},
Plan: Plan{
Template: "{{ .Title }}\n{{if .Result}}\n<pre><code>{{ .Result }}\n</pre></code>\n{{end}}\n<details><summary>Details (Click me)</summary>\n\n<pre><code>{{ .Body }}\n</pre></code></details>\n",
Template: "## Plan Result\n{{if .Result}}\n<pre><code>{{ .Result }}\n</pre></code>\n{{end}}\n<details><summary>Details (Click me)</summary>\n\n<pre><code>{{ .Body }}\n</pre></code></details>\n",
WhenDestroy: WhenDestroy{},
},
Apply: Apply{
Expand Down Expand Up @@ -70,7 +70,7 @@ func TestLoadFile(t *testing.T) {
Template: "",
},
Plan: Plan{
Template: "{{ .Title }}\n{{if .Result}}\n<pre><code>{{ .Result }}\n</pre></code>\n{{end}}\n<details><summary>Details (Click me)</summary>\n\n<pre><code>{{ .Body }}\n</pre></code></details>\n",
Template: "## Plan Result\n{{if .Result}}\n<pre><code>{{ .Result }}\n</pre></code>\n{{end}}\n<details><summary>Details (Click me)</summary>\n\n<pre><code>{{ .Body }}\n</pre></code></details>\n",
WhenAddOrUpdateOnly: WhenAddOrUpdateOnly{
Label: "add-or-update",
},
Expand Down Expand Up @@ -112,7 +112,7 @@ func TestLoadFile(t *testing.T) {
Template: "",
},
Plan: Plan{
Template: "{{ .Title }}\n{{if .Result}}\n<pre><code>{{ .Result }}\n</pre></code>\n{{end}}\n<details><summary>Details (Click me)</summary>\n\n<pre><code>{{ .Body }}\n</pre></code></details>\n",
Template: "## Plan Result\n{{if .Result}}\n<pre><code>{{ .Result }}\n</pre></code>\n{{end}}\n<details><summary>Details (Click me)</summary>\n\n<pre><code>{{ .Body }}\n</pre></code></details>\n",
WhenDestroy: WhenDestroy{},
},
Apply: Apply{
Expand Down
2 changes: 1 addition & 1 deletion example-use-raw-output.tfcmt.yaml
Expand Up @@ -9,7 +9,7 @@ terraform:
use_raw_output: true
plan:
template: |
{{ .Title }}
## Plan Result
{{if .Result}}
<pre><code>{{ .Result }}
</pre></code>
Expand Down
2 changes: 1 addition & 1 deletion example-with-destroy-and-result-labels.tfcmt.yaml
Expand Up @@ -8,7 +8,7 @@ notifier:
terraform:
plan:
template: |
{{ .Title }}
## Plan Result
{{if .Result}}
<pre><code>{{ .Result }}
</pre></code>
Expand Down
2 changes: 1 addition & 1 deletion example.tfcmt.yaml
Expand Up @@ -8,7 +8,7 @@ notifier:
terraform:
plan:
template: |
{{ .Title }}
## Plan Result
{{if .Result}}
<pre><code>{{ .Result }}
</pre></code>
Expand Down
27 changes: 2 additions & 25 deletions main.go
Expand Up @@ -109,11 +109,8 @@ func (t *tfcmt) getNotifier(ctx context.Context, ci CI) (notifier.Notifier, erro
Owner: t.config.Notifier.Github.Repository.Owner,
Repo: t.config.Notifier.Github.Repository.Name,
PR: github.PullRequest{
Revision: ci.PR.Revision,
Number: ci.PR.Number,
Title: t.context.String("title"),
DestroyWarningTitle: t.context.String("destroy-warning-title"),
DestroyWarningMessage: t.context.String("destroy-warning-message"),
Revision: ci.PR.Revision,
Number: ci.PR.Number,
},
CI: ci.URL,
Parser: t.parser,
Expand Down Expand Up @@ -189,31 +186,11 @@ func main() {
Name: "plan",
Usage: "Run terraform plan and post a comment to GitHub commit or pull request",
Action: cmdPlan,
Flags: []cli.Flag{
&cli.StringFlag{
Name: "title, t",
Usage: "Specify the title to use for notification",
},
&cli.StringFlag{
Name: "destroy-warning-title",
Usage: "Specify the title to use for destroy warning notification",
},
&cli.StringFlag{
Name: "destroy-warning-message",
Usage: "Specify the message to use for destroy warning notification",
},
},
},
{
Name: "apply",
Usage: "Run terraform apply and post a comment to GitHub commit or pull request",
Action: cmdApply,
Flags: []cli.Flag{
&cli.StringFlag{
Name: "title, t",
Usage: "Specify the title to use for notification",
},
},
},
{
Name: "version",
Expand Down
8 changes: 2 additions & 6 deletions notifier/github/client.go
Expand Up @@ -57,12 +57,8 @@ type Config struct {

// PullRequest represents GitHub Pull Request metadata
type PullRequest struct {
Revision string
Title string
Message string
Number int
DestroyWarningTitle string
DestroyWarningMessage string
Revision string
Number int
}

type service struct {
Expand Down
1 change: 0 additions & 1 deletion notifier/github/github_test.go
Expand Up @@ -131,7 +131,6 @@ func newFakeConfig() Config {
PR: PullRequest{
Revision: "abcd",
Number: 1,
Message: "message",
},
Parser: terraform.NewPlanParser(),
Template: terraform.NewPlanTemplate(terraform.DefaultPlanTemplate),
Expand Down
1 change: 0 additions & 1 deletion notifier/github/notify.go
Expand Up @@ -102,7 +102,6 @@ func (g *NotifyService) Notify(ctx context.Context, param notifier.ParamExec) (i
}

template.SetValue(terraform.CommonTemplate{
Title: cfg.PR.Title,
Result: result.Result,
Body: body,
Link: cfg.CI,
Expand Down
10 changes: 0 additions & 10 deletions notifier/github/notify_test.go
Expand Up @@ -27,7 +27,6 @@ func TestNotifyNotify(t *testing.T) {
PR: PullRequest{
Revision: "abcd",
Number: 1,
Message: "message",
},
Parser: terraform.NewPlanParser(),
Template: terraform.NewPlanTemplate(terraform.DefaultPlanTemplate),
Expand All @@ -50,7 +49,6 @@ func TestNotifyNotify(t *testing.T) {
PR: PullRequest{
Revision: "",
Number: 0,
Message: "message",
},
Parser: terraform.NewPlanParser(),
Template: terraform.NewPlanTemplate(terraform.DefaultPlanTemplate),
Expand All @@ -73,7 +71,6 @@ func TestNotifyNotify(t *testing.T) {
PR: PullRequest{
Revision: "",
Number: 1,
Message: "message",
},
Parser: terraform.NewPlanParser(),
Template: terraform.NewPlanTemplate(terraform.DefaultPlanTemplate),
Expand All @@ -96,7 +93,6 @@ func TestNotifyNotify(t *testing.T) {
PR: PullRequest{
Revision: "",
Number: 1,
Message: "message",
},
Parser: terraform.NewPlanParser(),
Template: terraform.NewPlanTemplate(terraform.DefaultPlanTemplate),
Expand All @@ -119,7 +115,6 @@ func TestNotifyNotify(t *testing.T) {
PR: PullRequest{
Revision: "revision-revision",
Number: 0,
Message: "message",
},
Parser: terraform.NewPlanParser(),
Template: terraform.NewPlanTemplate(terraform.DefaultPlanTemplate),
Expand All @@ -143,7 +138,6 @@ func TestNotifyNotify(t *testing.T) {
PR: PullRequest{
Revision: "",
Number: 1,
Message: "message",
},
Parser: terraform.NewPlanParser(),
Template: terraform.NewPlanTemplate(terraform.DefaultPlanTemplate),
Expand All @@ -169,7 +163,6 @@ func TestNotifyNotify(t *testing.T) {
PR: PullRequest{
Revision: "",
Number: 1,
Message: "message",
},
Parser: terraform.NewPlanParser(),
Template: terraform.NewPlanTemplate(terraform.DefaultPlanTemplate),
Expand Down Expand Up @@ -198,7 +191,6 @@ func TestNotifyNotify(t *testing.T) {
PR: PullRequest{
Revision: "",
Number: 1,
Message: "message",
},
Parser: terraform.NewPlanParser(),
Template: terraform.NewPlanTemplate(terraform.DefaultPlanTemplate),
Expand All @@ -223,7 +215,6 @@ func TestNotifyNotify(t *testing.T) {
PR: PullRequest{
Revision: "revision",
Number: 0, // For apply, it is always 0
Message: "message",
},
Parser: terraform.NewApplyParser(),
Template: terraform.NewApplyTemplate(terraform.DefaultApplyTemplate),
Expand All @@ -247,7 +238,6 @@ func TestNotifyNotify(t *testing.T) {
PR: PullRequest{
Revision: "Merge pull request #123 from suzuki-shunsuke/tfcmt",
Number: 0, // For apply, it is always 0
Message: "message",
},
Parser: terraform.NewApplyParser(),
Template: terraform.NewApplyTemplate(terraform.DefaultApplyTemplate),
Expand Down

0 comments on commit 37d7863

Please sign in to comment.