Skip to content

Commit

Permalink
explicitly say AddOrUpdateOnly
Browse files Browse the repository at this point in the history
  • Loading branch information
drlau committed May 28, 2020
1 parent 721ae86 commit 98a040e
Show file tree
Hide file tree
Showing 8 changed files with 75 additions and 75 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ terraform:
<pre><code>{{ .Body }}
</pre></code></details>
when_add_or_update:
when_add_or_update_only:
label: "add-or-update"
when_destroy:
label: "destroy"
Expand Down
14 changes: 7 additions & 7 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,15 +81,15 @@ type Fmt struct {

// Plan is a terraform plan config
type Plan struct {
Template string `yaml:"template"`
WhenAddOrUpdate WhenAddOrUpdate `yaml:"when_add_or_update,omitempty"`
WhenDestroy WhenDestroy `yaml:"when_destroy,omitempty"`
WhenNoChanges WhenNoChanges `yaml:"when_no_changes,omitempty"`
WhenPlanError WhenPlanError `yaml:"when_plan_error,omitempty"`
Template string `yaml:"template"`
WhenAddOrUpdateOnly WhenAddOrUpdateOnly `yaml:"when_add_or_update_only,omitempty"`
WhenDestroy WhenDestroy `yaml:"when_destroy,omitempty"`
WhenNoChanges WhenNoChanges `yaml:"when_no_changes,omitempty"`
WhenPlanError WhenPlanError `yaml:"when_plan_error,omitempty"`
}

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

Expand Down
2 changes: 1 addition & 1 deletion config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ func TestLoadFile(t *testing.T) {
},
Plan: Plan{
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",
WhenAddOrUpdate: WhenAddOrUpdate{
WhenAddOrUpdateOnly: WhenAddOrUpdateOnly{
Label: "add-or-update",
},
WhenDestroy: WhenDestroy{
Expand Down
2 changes: 1 addition & 1 deletion example-with-destroy-and-result-labels.tfnotify.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ terraform:
<pre><code>{{ .Body }}
</pre></code></details>
when_add_or_update:
when_add_or_update_only:
label: "add-or-update"
when_destroy:
label: "destroy"
Expand Down
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ func (t *tfnotify) Run() error {
DestroyWarningTemplate: t.destroyWarningTemplate,
WarnDestroy: t.warnDestroy,
ResultLabels: github.ResultLabels{
AddOrUpdateLabel: t.config.Terraform.Plan.WhenAddOrUpdate.Label,
AddOrUpdateLabel: t.config.Terraform.Plan.WhenAddOrUpdateOnly.Label,
DestroyLabel: t.config.Terraform.Plan.WhenDestroy.Label,
NoChangesLabel: t.config.Terraform.Plan.WhenNoChanges.Label,
PlanErrorLabel: t.config.Terraform.Plan.WhenPlanError.Label,
Expand Down
2 changes: 1 addition & 1 deletion notifier/github/notify.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func (g *NotifyService) Notify(body string) (exit int, err error) {
}
var labelToAdd string

if result.HasAddOrUpdate {
if result.HasAddOrUpdateOnly {
labelToAdd = cfg.ResultLabels.AddOrUpdateLabel
} else if result.HasDestroy {
labelToAdd = cfg.ResultLabels.DestroyLabel
Expand Down
30 changes: 15 additions & 15 deletions terraform/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ type Parser interface {

// ParseResult represents the result of parsed terraform execution
type ParseResult struct {
Result string
HasAddOrUpdate bool
HasDestroy bool
HasNoChanges bool
HasPlanError bool
ExitCode int
Error error
Result string
HasAddOrUpdateOnly bool
HasDestroy bool
HasNoChanges bool
HasPlanError bool
ExitCode int
Error error
}

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

hasDestroy := p.HasDestroy.MatchString(line)
hasNoChanges := p.HasNoChanges.MatchString(line)
HasAddOrUpdate := !hasNoChanges && !hasDestroy && !hasPlanError
HasAddOrUpdateOnly := !hasNoChanges && !hasDestroy && !hasPlanError

return ParseResult{
Result: result,
HasAddOrUpdate: HasAddOrUpdate,
HasDestroy: hasDestroy,
HasNoChanges: hasNoChanges,
HasPlanError: hasPlanError,
ExitCode: exitCode,
Error: nil,
Result: result,
HasAddOrUpdateOnly: HasAddOrUpdateOnly,
HasDestroy: hasDestroy,
HasNoChanges: hasNoChanges,
HasPlanError: hasPlanError,
ExitCode: exitCode,
Error: nil,
}
}

Expand Down
96 changes: 48 additions & 48 deletions terraform/parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -405,26 +405,26 @@ func TestPlanParserParse(t *testing.T) {
name: "plan ok pattern",
body: planSuccessResult,
result: ParseResult{
Result: "Plan: 1 to add, 0 to change, 0 to destroy.",
HasAddOrUpdate: true,
HasDestroy: false,
HasNoChanges: false,
HasPlanError: false,
ExitCode: 0,
Error: nil,
Result: "Plan: 1 to add, 0 to change, 0 to destroy.",
HasAddOrUpdateOnly: true,
HasDestroy: false,
HasNoChanges: false,
HasPlanError: false,
ExitCode: 0,
Error: nil,
},
},
{
name: "no stdin",
body: "",
result: ParseResult{
Result: "",
HasAddOrUpdate: false,
HasDestroy: false,
HasNoChanges: false,
HasPlanError: false,
ExitCode: 1,
Error: errors.New("cannot parse plan result"),
Result: "",
HasAddOrUpdateOnly: false,
HasDestroy: false,
HasNoChanges: false,
HasPlanError: false,
ExitCode: 1,
Error: errors.New("cannot parse plan result"),
},
},
{
Expand All @@ -437,64 +437,64 @@ func TestPlanParserParse(t *testing.T) {
* 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
* google_sql_user.proxyuser_main: 1 error(s) occurred:`,
HasAddOrUpdate: false,
HasDestroy: false,
HasNoChanges: false,
HasPlanError: true,
ExitCode: 1,
Error: nil,
HasAddOrUpdateOnly: false,
HasDestroy: false,
HasNoChanges: false,
HasPlanError: true,
ExitCode: 1,
Error: nil,
},
},
{
name: "plan no changes",
body: planNoChanges,
result: ParseResult{
Result: "No changes. Infrastructure is up-to-date.",
HasAddOrUpdate: false,
HasDestroy: false,
HasNoChanges: true,
HasPlanError: false,
ExitCode: 0,
Error: nil,
Result: "No changes. Infrastructure is up-to-date.",
HasAddOrUpdateOnly: false,
HasDestroy: false,
HasNoChanges: true,
HasPlanError: false,
ExitCode: 0,
Error: nil,
},
},
{
name: "plan has destroy",
body: planHasDestroy,
result: ParseResult{
Result: "Plan: 0 to add, 0 to change, 1 to destroy.",
HasAddOrUpdate: false,
HasDestroy: true,
HasNoChanges: false,
HasPlanError: false,
ExitCode: 0,
Error: nil,
Result: "Plan: 0 to add, 0 to change, 1 to destroy.",
HasAddOrUpdateOnly: false,
HasDestroy: true,
HasNoChanges: false,
HasPlanError: false,
ExitCode: 0,
Error: nil,
},
},
{
name: "plan has add and destroy",
body: planHasAddAndDestroy,
result: ParseResult{
Result: "Plan: 1 to add, 0 to change, 1 to destroy.",
HasAddOrUpdate: false,
HasDestroy: true,
HasNoChanges: false,
HasPlanError: false,
ExitCode: 0,
Error: nil,
Result: "Plan: 1 to add, 0 to change, 1 to destroy.",
HasAddOrUpdateOnly: false,
HasDestroy: true,
HasNoChanges: false,
HasPlanError: false,
ExitCode: 0,
Error: nil,
},
},
{
name: "plan has add and update in place",
body: planHasAddAndUpdateInPlace,
result: ParseResult{
Result: "Plan: 1 to add, 1 to change, 0 to destroy.",
HasAddOrUpdate: true,
HasDestroy: false,
HasNoChanges: false,
HasPlanError: false,
ExitCode: 0,
Error: nil,
Result: "Plan: 1 to add, 1 to change, 0 to destroy.",
HasAddOrUpdateOnly: true,
HasDestroy: false,
HasNoChanges: false,
HasPlanError: false,
ExitCode: 0,
Error: nil,
},
},
}
Expand Down

0 comments on commit 98a040e

Please sign in to comment.