Skip to content

Commit

Permalink
fix: remove title option
Browse files Browse the repository at this point in the history
BREAKING CHANGE: `--title` option and template variable "title" are removed
  • Loading branch information
suzuki-shunsuke committed Jan 19, 2021
1 parent 516a399 commit e6129fc
Show file tree
Hide file tree
Showing 13 changed files with 85 additions and 137 deletions.
8 changes: 3 additions & 5 deletions COMPARED_WITH_TFNOTIFY.md
Expand Up @@ -117,7 +117,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 +133,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 +192,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 +203,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 e6129fc

Please sign in to comment.