diff --git a/server/events/markdown_renderer.go b/server/events/markdown_renderer.go index eb05ba676e..47b6309ea4 100644 --- a/server/events/markdown_renderer.go +++ b/server/events/markdown_renderer.go @@ -76,6 +76,7 @@ type resultData struct { type planSuccessData struct { models.PlanSuccess + PlanSummary string PlanWasDeleted bool DisableApply bool DisableRepoLocking bool @@ -147,7 +148,7 @@ func (m *MarkdownRenderer) renderProjectResults(results []models.ProjectResult, }) } else if result.PlanSuccess != nil { if m.shouldUseWrappedTmpl(vcsHost, result.PlanSuccess.TerraformOutput) { - resultData.Rendered = m.renderTemplate(planSuccessWrappedTmpl, planSuccessData{PlanSuccess: *result.PlanSuccess, PlanWasDeleted: common.PlansDeleted, DisableApply: common.DisableApply, DisableRepoLocking: common.DisableRepoLocking}) + resultData.Rendered = m.renderTemplate(planSuccessWrappedTmpl, planSuccessData{PlanSuccess: *result.PlanSuccess, PlanSummary: result.PlanSuccess.Summary(), PlanWasDeleted: common.PlansDeleted, DisableApply: common.DisableApply, DisableRepoLocking: common.DisableRepoLocking}) } else { resultData.Rendered = m.renderTemplate(planSuccessUnwrappedTmpl, planSuccessData{PlanSuccess: *result.PlanSuccess, PlanWasDeleted: common.PlansDeleted, DisableApply: common.DisableApply, DisableRepoLocking: common.DisableRepoLocking}) } @@ -280,7 +281,8 @@ var planSuccessWrappedTmpl = template.Must(template.New("").Parse( "{{.TerraformOutput}}\n" + "```\n\n" + planNextSteps + "\n" + - "" + + "" + "\n" + + "{{.PlanSummary}}" + "{{ if .HasDiverged }}\n\n:warning: The branch we're merging into is ahead, it is recommended to pull new commits first.{{end}}")) var policyCheckSuccessUnwrappedTmpl = template.Must(template.New("").Parse( diff --git a/server/events/markdown_renderer_test.go b/server/events/markdown_renderer_test.go index c1c39358eb..c6ba1fe9e1 100644 --- a/server/events/markdown_renderer_test.go +++ b/server/events/markdown_renderer_test.go @@ -1210,7 +1210,7 @@ func TestRenderProjectResults_WrapSingleProject(t *testing.T) { }, { VCSHost: models.Github, - Output: strings.Repeat("line\n", 13), + Output: strings.Repeat("line\n", 13) + fmt.Sprintf("No changes. Infrastructure is up-to-date."), ShouldWrap: true, }, { @@ -1234,7 +1234,7 @@ func TestRenderProjectResults_WrapSingleProject(t *testing.T) { { VCSHost: models.Gitlab, GitlabCommonMarkSupport: true, - Output: strings.Repeat("line\n", 13), + Output: strings.Repeat("line\n", 13) + fmt.Sprintf("No changes. Infrastructure is up-to-date."), ShouldWrap: true, }, { @@ -1309,6 +1309,7 @@ $$$ * :repeat: To **plan** this project again, comment: * $replancmd$ +No changes. Infrastructure is up-to-date. --- * :fast_forward: To **apply** all unapplied plans from this pull request, comment: @@ -1414,7 +1415,7 @@ $$$ func TestRenderProjectResults_MultiProjectPlanWrapped(t *testing.T) { mr := events.MarkdownRenderer{} - tfOut := strings.Repeat("line\n", 13) + tfOut := strings.Repeat("line\n", 13) + fmt.Sprintf("Plan: 1 to add, 0 to change, 0 to destroy.") rendered := mr.Render(events.CommandResult{ ProjectResults: []models.ProjectResult{ { @@ -1457,6 +1458,7 @@ $$$ * :repeat: To **plan** this project again, comment: * $staging-replan-cmd$ +Plan: 1 to add, 0 to change, 0 to destroy. --- ### 2. dir: $.$ workspace: $production$ @@ -1472,6 +1474,7 @@ $$$ * :repeat: To **plan** this project again, comment: * $production-replan-cmd$ +Plan: 1 to add, 0 to change, 0 to destroy. --- * :fast_forward: To **apply** all unapplied plans from this pull request, comment: diff --git a/server/events/models/models.go b/server/events/models/models.go index 215d42540d..bb3236d67d 100644 --- a/server/events/models/models.go +++ b/server/events/models/models.go @@ -20,6 +20,7 @@ import ( "fmt" "net/url" paths "path" + "regexp" "strings" "time" @@ -491,6 +492,16 @@ type PlanSuccess struct { HasDiverged bool } +// Summary extracts one line summary of plan changes from TerraformOutput. +func (p *PlanSuccess) Summary() string { + r := regexp.MustCompile(`Plan: \d+ to add, \d+ to change, \d+ to destroy.`) + if match := r.FindString(p.TerraformOutput); match != "" { + return match + } + r = regexp.MustCompile(`No changes. Infrastructure is up-to-date.`) + return r.FindString(p.TerraformOutput) +} + // PolicyCheckSuccess is the result of a successful policy check run. type PolicyCheckSuccess struct { // PolicyCheckOutput is the output from policy check binary(conftest|opa) diff --git a/server/events/models/models_test.go b/server/events/models/models_test.go index 37e41f1529..65806c9284 100644 --- a/server/events/models/models_test.go +++ b/server/events/models/models_test.go @@ -484,6 +484,58 @@ func TestProjectResult_PlanStatus(t *testing.T) { } } +func TestPlanSuccess_Summary(t *testing.T) { + cases := []struct { + p models.ProjectResult + expResult string + }{ + { + p: models.ProjectResult{ + PlanSuccess: &models.PlanSuccess{ + TerraformOutput: ` + An execution plan has been generated and is shown below. + Resource actions are indicated with the following symbols: + - destroy + + Terraform will perform the following actions: + + - null_resource.hi[1] + + + Plan: 0 to add, 0 to change, 1 to destroy.`, + }, + }, + expResult: "Plan: 0 to add, 0 to change, 1 to destroy.", + }, + { + p: models.ProjectResult{ + PlanSuccess: &models.PlanSuccess{ + TerraformOutput: ` + An execution plan has been generated and is shown below. + Resource actions are indicated with the following symbols: + + No changes. Infrastructure is up-to-date.`, + }, + }, + expResult: "No changes. Infrastructure is up-to-date.", + }, + { + p: models.ProjectResult{ + PlanSuccess: &models.PlanSuccess{ + TerraformOutput: `No match, expect empty`, + }, + }, + expResult: "", + }, + } + + for _, c := range cases { + t.Run(c.expResult, func(t *testing.T) { + Equals(t, c.expResult, c.p.PlanSuccess.Summary()) + }) + } +} + func TestPullStatus_StatusCount(t *testing.T) { ps := models.PullStatus{ Projects: []models.ProjectStatus{ diff --git a/server/testfixtures/test-repos/automerge/exp-output-autoplan.txt b/server/testfixtures/test-repos/automerge/exp-output-autoplan.txt index 9517ae553c..5bf30f999a 100644 --- a/server/testfixtures/test-repos/automerge/exp-output-autoplan.txt +++ b/server/testfixtures/test-repos/automerge/exp-output-autoplan.txt @@ -29,6 +29,7 @@ Plan: 1 to add, 0 to change, 0 to destroy. * :repeat: To **plan** this project again, comment: * `atlantis plan -d dir1` +Plan: 1 to add, 0 to change, 0 to destroy. --- ### 2. dir: `dir2` workspace: `default` @@ -57,6 +58,7 @@ Plan: 1 to add, 0 to change, 0 to destroy. * :repeat: To **plan** this project again, comment: * `atlantis plan -d dir2` +Plan: 1 to add, 0 to change, 0 to destroy. --- * :fast_forward: To **apply** all unapplied plans from this pull request, comment: diff --git a/server/testfixtures/test-repos/modules-yaml/exp-output-autoplan.txt b/server/testfixtures/test-repos/modules-yaml/exp-output-autoplan.txt index 9b53b55d9c..8d5ed23455 100644 --- a/server/testfixtures/test-repos/modules-yaml/exp-output-autoplan.txt +++ b/server/testfixtures/test-repos/modules-yaml/exp-output-autoplan.txt @@ -32,6 +32,7 @@ Changes to Outputs: * :repeat: To **plan** this project again, comment: * `atlantis plan -d staging` +Plan: 1 to add, 0 to change, 0 to destroy. --- ### 2. dir: `production` workspace: `default` @@ -63,6 +64,7 @@ Changes to Outputs: * :repeat: To **plan** this project again, comment: * `atlantis plan -d production` +Plan: 1 to add, 0 to change, 0 to destroy. --- * :fast_forward: To **apply** all unapplied plans from this pull request, comment: diff --git a/server/testfixtures/test-repos/modules/exp-output-autoplan-only-staging.txt b/server/testfixtures/test-repos/modules/exp-output-autoplan-only-staging.txt index a1b516ccab..78301fa47d 100644 --- a/server/testfixtures/test-repos/modules/exp-output-autoplan-only-staging.txt +++ b/server/testfixtures/test-repos/modules/exp-output-autoplan-only-staging.txt @@ -28,6 +28,7 @@ Changes to Outputs: * :repeat: To **plan** this project again, comment: * `atlantis plan -d staging` +Plan: 1 to add, 0 to change, 0 to destroy. --- * :fast_forward: To **apply** all unapplied plans from this pull request, comment: diff --git a/server/testfixtures/test-repos/modules/exp-output-plan-production.txt b/server/testfixtures/test-repos/modules/exp-output-plan-production.txt index c7ab213ebe..6c6193b614 100644 --- a/server/testfixtures/test-repos/modules/exp-output-plan-production.txt +++ b/server/testfixtures/test-repos/modules/exp-output-plan-production.txt @@ -28,6 +28,7 @@ Changes to Outputs: * :repeat: To **plan** this project again, comment: * `atlantis plan -d production` +Plan: 1 to add, 0 to change, 0 to destroy. --- * :fast_forward: To **apply** all unapplied plans from this pull request, comment: diff --git a/server/testfixtures/test-repos/modules/exp-output-plan-staging.txt b/server/testfixtures/test-repos/modules/exp-output-plan-staging.txt index a1b516ccab..78301fa47d 100644 --- a/server/testfixtures/test-repos/modules/exp-output-plan-staging.txt +++ b/server/testfixtures/test-repos/modules/exp-output-plan-staging.txt @@ -28,6 +28,7 @@ Changes to Outputs: * :repeat: To **plan** this project again, comment: * `atlantis plan -d staging` +Plan: 1 to add, 0 to change, 0 to destroy. --- * :fast_forward: To **apply** all unapplied plans from this pull request, comment: diff --git a/server/testfixtures/test-repos/policy-checks-apply-reqs/exp-output-autoplan.txt b/server/testfixtures/test-repos/policy-checks-apply-reqs/exp-output-autoplan.txt index d278415b40..3d4f0ce50f 100644 --- a/server/testfixtures/test-repos/policy-checks-apply-reqs/exp-output-autoplan.txt +++ b/server/testfixtures/test-repos/policy-checks-apply-reqs/exp-output-autoplan.txt @@ -28,6 +28,7 @@ Changes to Outputs: * :repeat: To **plan** this project again, comment: * `atlantis plan -d .` +Plan: 1 to add, 0 to change, 0 to destroy. --- * :fast_forward: To **apply** all unapplied plans from this pull request, comment: diff --git a/server/testfixtures/test-repos/policy-checks-diff-owner/exp-output-autoplan.txt b/server/testfixtures/test-repos/policy-checks-diff-owner/exp-output-autoplan.txt index d278415b40..3d4f0ce50f 100644 --- a/server/testfixtures/test-repos/policy-checks-diff-owner/exp-output-autoplan.txt +++ b/server/testfixtures/test-repos/policy-checks-diff-owner/exp-output-autoplan.txt @@ -28,6 +28,7 @@ Changes to Outputs: * :repeat: To **plan** this project again, comment: * `atlantis plan -d .` +Plan: 1 to add, 0 to change, 0 to destroy. --- * :fast_forward: To **apply** all unapplied plans from this pull request, comment: diff --git a/server/testfixtures/test-repos/policy-checks-multi-projects/exp-output-autoplan.txt b/server/testfixtures/test-repos/policy-checks-multi-projects/exp-output-autoplan.txt index 77ef71ca99..0b2fc4713c 100644 --- a/server/testfixtures/test-repos/policy-checks-multi-projects/exp-output-autoplan.txt +++ b/server/testfixtures/test-repos/policy-checks-multi-projects/exp-output-autoplan.txt @@ -32,6 +32,7 @@ Changes to Outputs: * :repeat: To **plan** this project again, comment: * `atlantis plan -d dir1` +Plan: 1 to add, 0 to change, 0 to destroy. --- ### 2. dir: `dir2` workspace: `default` @@ -63,6 +64,7 @@ Changes to Outputs: * :repeat: To **plan** this project again, comment: * `atlantis plan -d dir2` +Plan: 1 to add, 0 to change, 0 to destroy. --- * :fast_forward: To **apply** all unapplied plans from this pull request, comment: diff --git a/server/testfixtures/test-repos/policy-checks/exp-output-autoplan.txt b/server/testfixtures/test-repos/policy-checks/exp-output-autoplan.txt index d278415b40..3d4f0ce50f 100644 --- a/server/testfixtures/test-repos/policy-checks/exp-output-autoplan.txt +++ b/server/testfixtures/test-repos/policy-checks/exp-output-autoplan.txt @@ -28,6 +28,7 @@ Changes to Outputs: * :repeat: To **plan** this project again, comment: * `atlantis plan -d .` +Plan: 1 to add, 0 to change, 0 to destroy. --- * :fast_forward: To **apply** all unapplied plans from this pull request, comment: diff --git a/server/testfixtures/test-repos/server-side-cfg/exp-output-autoplan.txt b/server/testfixtures/test-repos/server-side-cfg/exp-output-autoplan.txt index 97048307e8..fbc21130f3 100644 --- a/server/testfixtures/test-repos/server-side-cfg/exp-output-autoplan.txt +++ b/server/testfixtures/test-repos/server-side-cfg/exp-output-autoplan.txt @@ -36,6 +36,7 @@ postplan custom * :repeat: To **plan** this project again, comment: * `atlantis plan -d .` +Plan: 1 to add, 0 to change, 0 to destroy. --- ### 2. dir: `.` workspace: `staging` @@ -69,6 +70,7 @@ Changes to Outputs: * :repeat: To **plan** this project again, comment: * `atlantis plan -w staging` +Plan: 1 to add, 0 to change, 0 to destroy. --- * :fast_forward: To **apply** all unapplied plans from this pull request, comment: diff --git a/server/testfixtures/test-repos/simple-yaml/exp-output-autoplan.txt b/server/testfixtures/test-repos/simple-yaml/exp-output-autoplan.txt index d424ef8f9b..456b23a3f0 100644 --- a/server/testfixtures/test-repos/simple-yaml/exp-output-autoplan.txt +++ b/server/testfixtures/test-repos/simple-yaml/exp-output-autoplan.txt @@ -37,6 +37,7 @@ postplan * :repeat: To **plan** this project again, comment: * `atlantis plan -d .` +Plan: 1 to add, 0 to change, 0 to destroy. --- ### 2. dir: `.` workspace: `staging` @@ -69,6 +70,7 @@ Changes to Outputs: * :repeat: To **plan** this project again, comment: * `atlantis plan -w staging` +Plan: 1 to add, 0 to change, 0 to destroy. --- * :fast_forward: To **apply** all unapplied plans from this pull request, comment: diff --git a/server/testfixtures/test-repos/simple/exp-output-atlantis-plan-new-workspace.txt b/server/testfixtures/test-repos/simple/exp-output-atlantis-plan-new-workspace.txt index 4cdcc1680f..ef5440acdb 100644 --- a/server/testfixtures/test-repos/simple/exp-output-atlantis-plan-new-workspace.txt +++ b/server/testfixtures/test-repos/simple/exp-output-atlantis-plan-new-workspace.txt @@ -39,6 +39,7 @@ Changes to Outputs: * :repeat: To **plan** this project again, comment: * `atlantis plan -w new_workspace -- -var var=new_workspace` +Plan: 3 to add, 0 to change, 0 to destroy. --- * :fast_forward: To **apply** all unapplied plans from this pull request, comment: diff --git a/server/testfixtures/test-repos/simple/exp-output-atlantis-plan-var-overridden.txt b/server/testfixtures/test-repos/simple/exp-output-atlantis-plan-var-overridden.txt index c9a1a6b735..f7c157b41e 100644 --- a/server/testfixtures/test-repos/simple/exp-output-atlantis-plan-var-overridden.txt +++ b/server/testfixtures/test-repos/simple/exp-output-atlantis-plan-var-overridden.txt @@ -39,6 +39,7 @@ Changes to Outputs: * :repeat: To **plan** this project again, comment: * `atlantis plan -d . -- -var var=overridden` +Plan: 3 to add, 0 to change, 0 to destroy. --- * :fast_forward: To **apply** all unapplied plans from this pull request, comment: diff --git a/server/testfixtures/test-repos/simple/exp-output-atlantis-plan.txt b/server/testfixtures/test-repos/simple/exp-output-atlantis-plan.txt index b27975c0b2..cdace0a298 100644 --- a/server/testfixtures/test-repos/simple/exp-output-atlantis-plan.txt +++ b/server/testfixtures/test-repos/simple/exp-output-atlantis-plan.txt @@ -39,6 +39,7 @@ Changes to Outputs: * :repeat: To **plan** this project again, comment: * `atlantis plan -d . -- -var var=default_workspace` +Plan: 3 to add, 0 to change, 0 to destroy. --- * :fast_forward: To **apply** all unapplied plans from this pull request, comment: diff --git a/server/testfixtures/test-repos/simple/exp-output-autoplan.txt b/server/testfixtures/test-repos/simple/exp-output-autoplan.txt index dc2543cc16..e2f5e0f9a4 100644 --- a/server/testfixtures/test-repos/simple/exp-output-autoplan.txt +++ b/server/testfixtures/test-repos/simple/exp-output-autoplan.txt @@ -39,6 +39,7 @@ Changes to Outputs: * :repeat: To **plan** this project again, comment: * `atlantis plan -d .` +Plan: 3 to add, 0 to change, 0 to destroy. --- * :fast_forward: To **apply** all unapplied plans from this pull request, comment: diff --git a/server/testfixtures/test-repos/tfvars-yaml-no-autoplan/exp-output-plan-default.txt b/server/testfixtures/test-repos/tfvars-yaml-no-autoplan/exp-output-plan-default.txt index c580909e04..7f146e028f 100644 --- a/server/testfixtures/test-repos/tfvars-yaml-no-autoplan/exp-output-plan-default.txt +++ b/server/testfixtures/test-repos/tfvars-yaml-no-autoplan/exp-output-plan-default.txt @@ -29,6 +29,7 @@ Changes to Outputs: * :repeat: To **plan** this project again, comment: * `atlantis plan -p default` +Plan: 1 to add, 0 to change, 0 to destroy. --- * :fast_forward: To **apply** all unapplied plans from this pull request, comment: diff --git a/server/testfixtures/test-repos/tfvars-yaml-no-autoplan/exp-output-plan-staging.txt b/server/testfixtures/test-repos/tfvars-yaml-no-autoplan/exp-output-plan-staging.txt index 2422cd3c33..b05a3296fe 100644 --- a/server/testfixtures/test-repos/tfvars-yaml-no-autoplan/exp-output-plan-staging.txt +++ b/server/testfixtures/test-repos/tfvars-yaml-no-autoplan/exp-output-plan-staging.txt @@ -29,6 +29,7 @@ Changes to Outputs: * :repeat: To **plan** this project again, comment: * `atlantis plan -p staging` +Plan: 1 to add, 0 to change, 0 to destroy. --- * :fast_forward: To **apply** all unapplied plans from this pull request, comment: diff --git a/server/testfixtures/test-repos/tfvars-yaml/exp-output-autoplan.txt b/server/testfixtures/test-repos/tfvars-yaml/exp-output-autoplan.txt index 66b428be32..dd7fb7a49a 100644 --- a/server/testfixtures/test-repos/tfvars-yaml/exp-output-autoplan.txt +++ b/server/testfixtures/test-repos/tfvars-yaml/exp-output-autoplan.txt @@ -35,6 +35,7 @@ workspace=default * :repeat: To **plan** this project again, comment: * `atlantis plan -p default` +Plan: 1 to add, 0 to change, 0 to destroy. --- ### 2. project: `staging` dir: `.` workspace: `default` @@ -67,6 +68,7 @@ Changes to Outputs: * :repeat: To **plan** this project again, comment: * `atlantis plan -p staging` +Plan: 1 to add, 0 to change, 0 to destroy. --- * :fast_forward: To **apply** all unapplied plans from this pull request, comment: