Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: PR check status to show summary e.g. Plan: 1 to add, 0 to change, 1 to destroy #2983

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion server/controllers/events/events_controller_e2e_test.go
Original file line number Diff line number Diff line change
@@ -1068,6 +1068,7 @@ func setupE2E(t *testing.T, repoDir string, opt setupOption) (events_controllers
parallelPoolSize := 1
silenceNoProjects := false

statusUpdater := runtimemocks.NewMockStatusUpdater()
commitStatusUpdater := mocks.NewMockCommitStatusUpdater()
asyncTfExec := runtimemocks.NewMockAsyncTFExec()

@@ -1143,7 +1144,7 @@ func setupE2E(t *testing.T, repoDir string, opt setupOption) (events_controllers
PlanStepRunner: runtime.NewPlanStepRunner(
terraformClient,
defaultTFVersion,
commitStatusUpdater,
statusUpdater,
asyncTfExec,
),
ShowStepRunner: showStepRunner,
2 changes: 1 addition & 1 deletion server/core/runtime/apply_step_runner.go
Original file line number Diff line number Diff line change
@@ -126,7 +126,7 @@ func (a *ApplyStepRunner) runRemoteApply(

// updateStatusF will update the commit status and log any error.
updateStatusF := func(status models.CommitStatus, url string) {
if err := a.CommitStatusUpdater.UpdateProject(ctx, command.Apply, status, url); err != nil {
if err := a.CommitStatusUpdater.UpdateProject(ctx, command.Apply, status, url, nil); err != nil {
ctx.Log.Err("unable to update status: %s", err)
}
}
10 changes: 5 additions & 5 deletions server/core/runtime/apply_step_runner_test.go
Original file line number Diff line number Diff line change
@@ -12,11 +12,11 @@ import (
. "github.com/petergtz/pegomock"
"github.com/pkg/errors"
"github.com/runatlantis/atlantis/server/core/runtime"
runtimemocks "github.com/runatlantis/atlantis/server/core/runtime/mocks"
runtimemodels "github.com/runatlantis/atlantis/server/core/runtime/models"
"github.com/runatlantis/atlantis/server/core/terraform/mocks"
matchers2 "github.com/runatlantis/atlantis/server/core/terraform/mocks/matchers"
"github.com/runatlantis/atlantis/server/events/command"
mocks2 "github.com/runatlantis/atlantis/server/events/mocks"
"github.com/runatlantis/atlantis/server/events/mocks/matchers"
"github.com/runatlantis/atlantis/server/events/models"
"github.com/runatlantis/atlantis/server/logging"
@@ -241,7 +241,7 @@ Plan: 0 to add, 0 to change, 1 to destroy.`
RegisterMockTestingT(t)
tfOut := fmt.Sprintf(preConfirmOutFmt, planFileContents) + postConfirmOut
tfExec := &remoteApplyMock{LinesToSend: tfOut, DoneCh: make(chan bool)}
updater := mocks2.NewMockCommitStatusUpdater()
updater := runtimemocks.NewMockStatusUpdater()
o := runtime.ApplyStepRunner{
AsyncTFExec: tfExec,
CommitStatusUpdater: updater,
@@ -273,8 +273,8 @@ Apply complete! Resources: 0 added, 0 changed, 1 destroyed.

// Check that the status was updated with the run url.
runURL := "https://app.terraform.io/app/lkysow-enterprises/atlantis-tfe-test-dir2/runs/run-PiDsRYKGcerTttV2"
updater.VerifyWasCalledOnce().UpdateProject(ctx, command.Apply, models.PendingCommitStatus, runURL)
updater.VerifyWasCalledOnce().UpdateProject(ctx, command.Apply, models.SuccessCommitStatus, runURL)
updater.VerifyWasCalledOnce().UpdateProject(ctx, command.Apply, models.PendingCommitStatus, runURL, nil)
updater.VerifyWasCalledOnce().UpdateProject(ctx, command.Apply, models.SuccessCommitStatus, runURL, nil)
}

// Test that if the plan is different, we error out.
@@ -304,7 +304,7 @@ Plan: 0 to add, 0 to change, 1 to destroy.`
}
o := runtime.ApplyStepRunner{
AsyncTFExec: tfExec,
CommitStatusUpdater: mocks2.NewMockCommitStatusUpdater(),
CommitStatusUpdater: runtimemocks.NewMockStatusUpdater(),
}
tfVersion, _ := version.NewVersion("0.11.0")

33 changes: 33 additions & 0 deletions server/core/runtime/mocks/matchers/command_name.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

33 changes: 33 additions & 0 deletions server/core/runtime/mocks/matchers/models_commitstatus.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

122 changes: 122 additions & 0 deletions server/core/runtime/mocks/mock_status_updater.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion server/core/runtime/plan_step_runner.go
Original file line number Diff line number Diff line change
@@ -198,7 +198,7 @@ func (p *planStepRunner) runRemotePlan(

// updateStatusF will update the commit status and log any error.
updateStatusF := func(status models.CommitStatus, url string) {
if err := p.CommitStatusUpdater.UpdateProject(ctx, command.Plan, status, url); err != nil {
if err := p.CommitStatusUpdater.UpdateProject(ctx, command.Plan, status, url, nil); err != nil {
ctx.Log.Err("unable to update status: %s", err)
}
}
22 changes: 10 additions & 12 deletions server/core/runtime/plan_step_runner_test.go
Original file line number Diff line number Diff line change
@@ -8,16 +8,14 @@ import (
"testing"

"github.com/hashicorp/go-version"
runtimemocks "github.com/runatlantis/atlantis/server/core/runtime/mocks"
"github.com/runatlantis/atlantis/server/events/command"
eventsmocks "github.com/runatlantis/atlantis/server/events/mocks"

. "github.com/petergtz/pegomock"
"github.com/pkg/errors"
"github.com/runatlantis/atlantis/server/core/runtime"
runtimemocks "github.com/runatlantis/atlantis/server/core/runtime/mocks"
runtimemodels "github.com/runatlantis/atlantis/server/core/runtime/models"
"github.com/runatlantis/atlantis/server/core/terraform/mocks"
matchers2 "github.com/runatlantis/atlantis/server/core/terraform/mocks/matchers"
"github.com/runatlantis/atlantis/server/events/command"
"github.com/runatlantis/atlantis/server/events/mocks/matchers"
"github.com/runatlantis/atlantis/server/events/models"
"github.com/runatlantis/atlantis/server/logging"
@@ -29,7 +27,7 @@ func TestRun_AddsEnvVarFile(t *testing.T) {
// Test that if env/workspace.tfvars file exists we use -var-file option.
RegisterMockTestingT(t)
terraform := mocks.NewMockClient()
commitStatusUpdater := eventsmocks.NewMockCommitStatusUpdater()
commitStatusUpdater := runtimemocks.NewMockStatusUpdater()
asyncTfExec := runtimemocks.NewMockAsyncTFExec()

// Create the env/workspace.tfvars file.
@@ -98,7 +96,7 @@ func TestRun_UsesDiffPathForProject(t *testing.T) {
// file.
RegisterMockTestingT(t)
terraform := mocks.NewMockClient()
commitStatusUpdater := eventsmocks.NewMockCommitStatusUpdater()
commitStatusUpdater := runtimemocks.NewMockStatusUpdater()
asyncTfExec := runtimemocks.NewMockAsyncTFExec()
tfVersion, _ := version.NewVersion("0.10.0")
logger := logging.NewNoopLogger(t)
@@ -178,7 +176,7 @@ Terraform will perform the following actions:
`
RegisterMockTestingT(t)
terraform := mocks.NewMockClient()
commitStatusUpdater := eventsmocks.NewMockCommitStatusUpdater()
commitStatusUpdater := runtimemocks.NewMockStatusUpdater()
asyncTfExec := runtimemocks.NewMockAsyncTFExec()
tfVersion, _ := version.NewVersion("0.10.0")
s := runtime.NewPlanStepRunner(terraform, tfVersion, commitStatusUpdater, asyncTfExec)
@@ -229,7 +227,7 @@ Terraform will perform the following actions:
func TestRun_OutputOnErr(t *testing.T) {
RegisterMockTestingT(t)
terraform := mocks.NewMockClient()
commitStatusUpdater := eventsmocks.NewMockCommitStatusUpdater()
commitStatusUpdater := runtimemocks.NewMockStatusUpdater()
asyncTfExec := runtimemocks.NewMockAsyncTFExec()
tfVersion, _ := version.NewVersion("0.10.0")
s := runtime.NewPlanStepRunner(terraform, tfVersion, commitStatusUpdater, asyncTfExec)
@@ -294,7 +292,7 @@ func TestRun_NoOptionalVarsIn012(t *testing.T) {
for _, c := range cases {
t.Run(c.name, func(t *testing.T) {
terraform := mocks.NewMockClient()
commitStatusUpdater := eventsmocks.NewMockCommitStatusUpdater()
commitStatusUpdater := runtimemocks.NewMockStatusUpdater()
asyncTfExec := runtimemocks.NewMockAsyncTFExec()
When(terraform.RunCommandWithVersion(
matchers.AnyCommandProjectContext(),
@@ -392,7 +390,7 @@ locally at this time.
}
RegisterMockTestingT(t)
terraform := mocks.NewMockClient()
commitStatusUpdater := eventsmocks.NewMockCommitStatusUpdater()
commitStatusUpdater := runtimemocks.NewMockStatusUpdater()
tfVersion, _ := version.NewVersion(c.tfVersion)
asyncTf := &remotePlanMock{}
s := runtime.NewPlanStepRunner(terraform, tfVersion, commitStatusUpdater, asyncTf)
@@ -471,8 +469,8 @@ Plan: 0 to add, 0 to change, 1 to destroy.`), "expect plan success")

// Ensure that the status was updated with the runURL.
runURL := "https://app.terraform.io/app/lkysow-enterprises/atlantis-tfe-test/runs/run-is4oVvJfrkud1KvE"
commitStatusUpdater.VerifyWasCalledOnce().UpdateProject(ctx, command.Plan, models.PendingCommitStatus, runURL)
commitStatusUpdater.VerifyWasCalledOnce().UpdateProject(ctx, command.Plan, models.SuccessCommitStatus, runURL)
commitStatusUpdater.VerifyWasCalledOnce().UpdateProject(ctx, command.Plan, models.PendingCommitStatus, runURL, nil)
commitStatusUpdater.VerifyWasCalledOnce().UpdateProject(ctx, command.Plan, models.SuccessCommitStatus, runURL, nil)
})
}
}
4 changes: 3 additions & 1 deletion server/core/runtime/runtime.go
Original file line number Diff line number Diff line change
@@ -48,8 +48,10 @@ type AsyncTFExec interface {

// StatusUpdater brings the interface from CommitStatusUpdater into this package
// without causing circular imports.
//
//go:generate pegomock generate -m --package mocks -o mocks/mock_status_updater.go StatusUpdater
type StatusUpdater interface {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are there tests that we can add to runetime_test.go ?

Copy link
Contributor Author

@krrrr38 krrrr38 Jan 14, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

StatusUpdater is just interface and this impl is DefaultCommitStatusUpdater. This test is implemented in commit_status_updater_test.go, so not needed 👌

StatusUpdater brings the interface from CommitStatusUpdater into this package without causing circular imports.

image

UpdateProject(ctx command.ProjectContext, cmdName command.Name, status models.CommitStatus, url string) error
UpdateProject(ctx command.ProjectContext, cmdName command.Name, status models.CommitStatus, url string, result *command.ProjectResult) error
}

// Runner mirrors events.StepRunner as a way to bring it into this package
Loading