Skip to content

Commit 98a040e

Browse files
committed
explicitly say AddOrUpdateOnly
1 parent 721ae86 commit 98a040e

File tree

8 files changed

+75
-75
lines changed

8 files changed

+75
-75
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ terraform:
174174
175175
<pre><code>{{ .Body }}
176176
</pre></code></details>
177-
when_add_or_update:
177+
when_add_or_update_only:
178178
label: "add-or-update"
179179
when_destroy:
180180
label: "destroy"

config/config.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -81,15 +81,15 @@ type Fmt struct {
8181

8282
// Plan is a terraform plan config
8383
type Plan struct {
84-
Template string `yaml:"template"`
85-
WhenAddOrUpdate WhenAddOrUpdate `yaml:"when_add_or_update,omitempty"`
86-
WhenDestroy WhenDestroy `yaml:"when_destroy,omitempty"`
87-
WhenNoChanges WhenNoChanges `yaml:"when_no_changes,omitempty"`
88-
WhenPlanError WhenPlanError `yaml:"when_plan_error,omitempty"`
84+
Template string `yaml:"template"`
85+
WhenAddOrUpdateOnly WhenAddOrUpdateOnly `yaml:"when_add_or_update_only,omitempty"`
86+
WhenDestroy WhenDestroy `yaml:"when_destroy,omitempty"`
87+
WhenNoChanges WhenNoChanges `yaml:"when_no_changes,omitempty"`
88+
WhenPlanError WhenPlanError `yaml:"when_plan_error,omitempty"`
8989
}
9090

91-
// WhenAddOrUpdate is a configuration to notify the plan result contains new or updated in place resources
92-
type WhenAddOrUpdate struct {
91+
// WhenAddOrUpdateOnly is a configuration to notify the plan result contains new or updated in place resources
92+
type WhenAddOrUpdateOnly struct {
9393
Label string `yaml:"label,omitempty"`
9494
}
9595

config/config_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ func TestLoadFile(t *testing.T) {
9393
},
9494
Plan: Plan{
9595
Template: "{{ .Title }}\n{{ .Message }}\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",
96-
WhenAddOrUpdate: WhenAddOrUpdate{
96+
WhenAddOrUpdateOnly: WhenAddOrUpdateOnly{
9797
Label: "add-or-update",
9898
},
9999
WhenDestroy: WhenDestroy{

example-with-destroy-and-result-labels.tfnotify.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ terraform:
1818
1919
<pre><code>{{ .Body }}
2020
</pre></code></details>
21-
when_add_or_update:
21+
when_add_or_update_only:
2222
label: "add-or-update"
2323
when_destroy:
2424
label: "destroy"

main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ func (t *tfnotify) Run() error {
116116
DestroyWarningTemplate: t.destroyWarningTemplate,
117117
WarnDestroy: t.warnDestroy,
118118
ResultLabels: github.ResultLabels{
119-
AddOrUpdateLabel: t.config.Terraform.Plan.WhenAddOrUpdate.Label,
119+
AddOrUpdateLabel: t.config.Terraform.Plan.WhenAddOrUpdateOnly.Label,
120120
DestroyLabel: t.config.Terraform.Plan.WhenDestroy.Label,
121121
NoChangesLabel: t.config.Terraform.Plan.WhenNoChanges.Label,
122122
PlanErrorLabel: t.config.Terraform.Plan.WhenPlanError.Label,

notifier/github/notify.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ func (g *NotifyService) Notify(body string) (exit int, err error) {
3939
}
4040
var labelToAdd string
4141

42-
if result.HasAddOrUpdate {
42+
if result.HasAddOrUpdateOnly {
4343
labelToAdd = cfg.ResultLabels.AddOrUpdateLabel
4444
} else if result.HasDestroy {
4545
labelToAdd = cfg.ResultLabels.DestroyLabel

terraform/parser.go

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@ type Parser interface {
1313

1414
// ParseResult represents the result of parsed terraform execution
1515
type ParseResult struct {
16-
Result string
17-
HasAddOrUpdate bool
18-
HasDestroy bool
19-
HasNoChanges bool
20-
HasPlanError bool
21-
ExitCode int
22-
Error error
16+
Result string
17+
HasAddOrUpdateOnly bool
18+
HasDestroy bool
19+
HasNoChanges bool
20+
HasPlanError bool
21+
ExitCode int
22+
Error error
2323
}
2424

2525
// DefaultParser is a parser for terraform commands
@@ -130,16 +130,16 @@ func (p *PlanParser) Parse(body string) ParseResult {
130130

131131
hasDestroy := p.HasDestroy.MatchString(line)
132132
hasNoChanges := p.HasNoChanges.MatchString(line)
133-
HasAddOrUpdate := !hasNoChanges && !hasDestroy && !hasPlanError
133+
HasAddOrUpdateOnly := !hasNoChanges && !hasDestroy && !hasPlanError
134134

135135
return ParseResult{
136-
Result: result,
137-
HasAddOrUpdate: HasAddOrUpdate,
138-
HasDestroy: hasDestroy,
139-
HasNoChanges: hasNoChanges,
140-
HasPlanError: hasPlanError,
141-
ExitCode: exitCode,
142-
Error: nil,
136+
Result: result,
137+
HasAddOrUpdateOnly: HasAddOrUpdateOnly,
138+
HasDestroy: hasDestroy,
139+
HasNoChanges: hasNoChanges,
140+
HasPlanError: hasPlanError,
141+
ExitCode: exitCode,
142+
Error: nil,
143143
}
144144
}
145145

terraform/parser_test.go

Lines changed: 48 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -405,26 +405,26 @@ func TestPlanParserParse(t *testing.T) {
405405
name: "plan ok pattern",
406406
body: planSuccessResult,
407407
result: ParseResult{
408-
Result: "Plan: 1 to add, 0 to change, 0 to destroy.",
409-
HasAddOrUpdate: true,
410-
HasDestroy: false,
411-
HasNoChanges: false,
412-
HasPlanError: false,
413-
ExitCode: 0,
414-
Error: nil,
408+
Result: "Plan: 1 to add, 0 to change, 0 to destroy.",
409+
HasAddOrUpdateOnly: true,
410+
HasDestroy: false,
411+
HasNoChanges: false,
412+
HasPlanError: false,
413+
ExitCode: 0,
414+
Error: nil,
415415
},
416416
},
417417
{
418418
name: "no stdin",
419419
body: "",
420420
result: ParseResult{
421-
Result: "",
422-
HasAddOrUpdate: false,
423-
HasDestroy: false,
424-
HasNoChanges: false,
425-
HasPlanError: false,
426-
ExitCode: 1,
427-
Error: errors.New("cannot parse plan result"),
421+
Result: "",
422+
HasAddOrUpdateOnly: false,
423+
HasDestroy: false,
424+
HasNoChanges: false,
425+
HasPlanError: false,
426+
ExitCode: 1,
427+
Error: errors.New("cannot parse plan result"),
428428
},
429429
},
430430
{
@@ -437,64 +437,64 @@ func TestPlanParserParse(t *testing.T) {
437437
438438
* google_sql_database.main: google_sql_database.main: Error reading SQL Database "main" in instance "main-master-instance": googleapi: Error 409: The instance or operation is not in an appropriate state to handle the request., invalidState
439439
* google_sql_user.proxyuser_main: 1 error(s) occurred:`,
440-
HasAddOrUpdate: false,
441-
HasDestroy: false,
442-
HasNoChanges: false,
443-
HasPlanError: true,
444-
ExitCode: 1,
445-
Error: nil,
440+
HasAddOrUpdateOnly: false,
441+
HasDestroy: false,
442+
HasNoChanges: false,
443+
HasPlanError: true,
444+
ExitCode: 1,
445+
Error: nil,
446446
},
447447
},
448448
{
449449
name: "plan no changes",
450450
body: planNoChanges,
451451
result: ParseResult{
452-
Result: "No changes. Infrastructure is up-to-date.",
453-
HasAddOrUpdate: false,
454-
HasDestroy: false,
455-
HasNoChanges: true,
456-
HasPlanError: false,
457-
ExitCode: 0,
458-
Error: nil,
452+
Result: "No changes. Infrastructure is up-to-date.",
453+
HasAddOrUpdateOnly: false,
454+
HasDestroy: false,
455+
HasNoChanges: true,
456+
HasPlanError: false,
457+
ExitCode: 0,
458+
Error: nil,
459459
},
460460
},
461461
{
462462
name: "plan has destroy",
463463
body: planHasDestroy,
464464
result: ParseResult{
465-
Result: "Plan: 0 to add, 0 to change, 1 to destroy.",
466-
HasAddOrUpdate: false,
467-
HasDestroy: true,
468-
HasNoChanges: false,
469-
HasPlanError: false,
470-
ExitCode: 0,
471-
Error: nil,
465+
Result: "Plan: 0 to add, 0 to change, 1 to destroy.",
466+
HasAddOrUpdateOnly: false,
467+
HasDestroy: true,
468+
HasNoChanges: false,
469+
HasPlanError: false,
470+
ExitCode: 0,
471+
Error: nil,
472472
},
473473
},
474474
{
475475
name: "plan has add and destroy",
476476
body: planHasAddAndDestroy,
477477
result: ParseResult{
478-
Result: "Plan: 1 to add, 0 to change, 1 to destroy.",
479-
HasAddOrUpdate: false,
480-
HasDestroy: true,
481-
HasNoChanges: false,
482-
HasPlanError: false,
483-
ExitCode: 0,
484-
Error: nil,
478+
Result: "Plan: 1 to add, 0 to change, 1 to destroy.",
479+
HasAddOrUpdateOnly: false,
480+
HasDestroy: true,
481+
HasNoChanges: false,
482+
HasPlanError: false,
483+
ExitCode: 0,
484+
Error: nil,
485485
},
486486
},
487487
{
488488
name: "plan has add and update in place",
489489
body: planHasAddAndUpdateInPlace,
490490
result: ParseResult{
491-
Result: "Plan: 1 to add, 1 to change, 0 to destroy.",
492-
HasAddOrUpdate: true,
493-
HasDestroy: false,
494-
HasNoChanges: false,
495-
HasPlanError: false,
496-
ExitCode: 0,
497-
Error: nil,
491+
Result: "Plan: 1 to add, 1 to change, 0 to destroy.",
492+
HasAddOrUpdateOnly: true,
493+
HasDestroy: false,
494+
HasNoChanges: false,
495+
HasPlanError: false,
496+
ExitCode: 0,
497+
Error: nil,
498498
},
499499
},
500500
}

0 commit comments

Comments
 (0)