From d11a927d7d9fd47a74908e2bfca40834040ce62d Mon Sep 17 00:00:00 2001 From: Luke Kysow Date: Mon, 16 Jul 2018 17:24:29 +0200 Subject: [PATCH] Don't comment back on autoplan no projects. --- CHANGELOG.md | 21 +++++++++++++++++++ server/events/command_runner.go | 7 +++++++ server/events/markdown_renderer.go | 5 ----- server/events/markdown_renderer_test.go | 15 ++++++------- server/events_controller_e2e_test.go | 19 +++++++++++------ .../exp-output-autoplan-only-modules.txt | 2 -- 6 files changed, 47 insertions(+), 22 deletions(-) delete mode 100644 server/testfixtures/test-repos/modules/exp-output-autoplan-only-modules.txt diff --git a/CHANGELOG.md b/CHANGELOG.md index 3e4f00b00..e744e83d6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,24 @@ +# v0.4.2 + +## Features +* Don't comment on pull request if autoplan determines there are no projects to plan in. +This was getting very noisy for users who use their repos for more than just Terraform ([#183](https://github.com/runatlantis/atlantis/issues/183)). + +## Bugfixes +None + +## Backwards Incompatibilities / Notes: +None + +## Downloads +* [atlantis_darwin_amd64.zip](https://github.com/runatlantis/atlantis/releases/download/v0.4.2/atlantis_darwin_amd64.zip) +* [atlantis_linux_386.zip](https://github.com/runatlantis/atlantis/releases/download/v0.4.2/atlantis_linux_386.zip) +* [atlantis_linux_amd64.zip](https://github.com/runatlantis/atlantis/releases/download/v0.4.2/atlantis_linux_amd64.zip) +* [atlantis_linux_arm.zip](https://github.com/runatlantis/atlantis/releases/download/v0.4.2/atlantis_linux_arm.zip) + +## Docker +`runatlantis/atlantis:v0.4.2` + # v0.4.1 ## Features diff --git a/server/events/command_runner.go b/server/events/command_runner.go index 04fbb7f12..330788201 100644 --- a/server/events/command_runner.go +++ b/server/events/command_runner.go @@ -93,6 +93,13 @@ func (c *DefaultCommandRunner) RunAutoplanCommand(baseRepo models.Repo, headRepo c.updatePull(ctx, AutoplanCommand{}, CommandResult{Error: err}) return } + if len(projectCmds) == 0 { + log.Info("determined there was no project to run plan in") + if err := c.CommitStatusUpdater.Update(baseRepo, pull, vcs.Success, Plan); err != nil { + ctx.Log.Warn("unable to update commit status: %s", err) + } + return + } var results []ProjectResult for _, cmd := range projectCmds { diff --git a/server/events/markdown_renderer.go b/server/events/markdown_renderer.go index d21a683d7..0d631a0a0 100644 --- a/server/events/markdown_renderer.go +++ b/server/events/markdown_renderer.go @@ -67,9 +67,6 @@ func (m *MarkdownRenderer) Render(res CommandResult, cmdName CommandName, log st if res.Failure != "" { return m.renderTemplate(failureWithLogTmpl, FailureData{res.Failure, common}) } - if len(res.ProjectResults) == 0 && autoplan { - return m.renderTemplate(autoplanNoProjectsWithLogTmpl, common) - } return m.renderProjectResults(res.ProjectResults, common) } @@ -148,11 +145,9 @@ var errTmplText = "**{{.Command}} Error**\n" + "```\n" + "{{.Error}}\n" + "```\n" -var autoplanNoProjectsTmplText = "Ran `plan` in 0 projects because Atlantis detected no Terraform changes or could not determine where to run `plan`.\n" var errTmpl = template.Must(template.New("").Parse(errTmplText)) var errWithLogTmpl = template.Must(template.New("").Parse(errTmplText + logTmpl)) var failureTmplText = "**{{.Command}} Failed**: {{.Failure}}\n" var failureTmpl = template.Must(template.New("").Parse(failureTmplText)) var failureWithLogTmpl = template.Must(template.New("").Parse(failureTmplText + logTmpl)) -var autoplanNoProjectsWithLogTmpl = template.Must(template.New("").Parse(autoplanNoProjectsTmplText + logTmpl)) var logTmpl = "{{if .Verbose}}\n
Log\n

\n\n```\n{{.Log}}```\n

{{end}}\n" diff --git a/server/events/markdown_renderer_test.go b/server/events/markdown_renderer_test.go index 88c19ad1f..85a83414d 100644 --- a/server/events/markdown_renderer_test.go +++ b/server/events/markdown_renderer_test.go @@ -113,15 +113,6 @@ func TestRenderErrAndFailure(t *testing.T) { Equals(t, "**Plan Error**\n```\nerror\n```\n\n", s) } -func TestRenderAutoplanNoResults(t *testing.T) { - // If there are no project results during an autoplan we should still comment - // back because the user might expect some output. - r := events.MarkdownRenderer{} - res := events.CommandResult{} - s := r.Render(res, events.Plan, "", false, true) - Equals(t, "Ran `plan` in 0 projects because Atlantis detected no Terraform changes or could not determine where to run `plan`.\n\n", s) -} - func TestRenderProjectResults(t *testing.T) { cases := []struct { Description string @@ -129,6 +120,12 @@ func TestRenderProjectResults(t *testing.T) { ProjectResults []events.ProjectResult Expected string }{ + { + "no projects", + events.Plan, + []events.ProjectResult{}, + "Ran Plan for 0 projects:\n\n\n", + }, { "single successful plan", events.Plan, diff --git a/server/events_controller_e2e_test.go b/server/events_controller_e2e_test.go index d69471cb2..1e59e8cc6 100644 --- a/server/events_controller_e2e_test.go +++ b/server/events_controller_e2e_test.go @@ -35,8 +35,6 @@ func TestGitHubWorkflow(t *testing.T) { if testing.Short() { t.SkipNow() } - RegisterMockTestingT(t) - cases := []struct { Description string // RepoDir is relative to testfixtures/test-repos. @@ -105,7 +103,7 @@ func TestGitHubWorkflow(t *testing.T) { Description: "modules modules only", RepoDir: "modules", ModifiedFiles: []string{"modules/null/main.tf"}, - ExpAutoplanCommentFile: "exp-output-autoplan-only-modules.txt", + ExpAutoplanCommentFile: "", CommentAndReplies: []string{ "atlantis plan -d staging", "exp-output-plan-staging.txt", "atlantis plan -d production", "exp-output-plan-production.txt", @@ -152,6 +150,8 @@ func TestGitHubWorkflow(t *testing.T) { } for _, c := range cases { t.Run(c.Description, func(t *testing.T) { + RegisterMockTestingT(t) + ctrl, vcsClient, githubGetter, atlantisWorkspace := setupE2E(t) // Set the repo to be cloned through the testing backdoor. repoDir, headSHA, cleanup := initializeRepo(t, c.RepoDir) @@ -162,12 +162,14 @@ func TestGitHubWorkflow(t *testing.T) { w := httptest.NewRecorder() When(githubGetter.GetPullRequest(AnyRepo(), AnyInt())).ThenReturn(GitHubPullRequestParsed(headSHA), nil) When(vcsClient.GetModifiedFiles(AnyRepo(), matchers.AnyModelsPullRequest())).ThenReturn(c.ModifiedFiles, nil) + expNumTimesCalledCreateComment := 0 // First, send the open pull request event and trigger an autoplan. pullOpenedReq := GitHubPullRequestOpenedEvent(t, headSHA) ctrl.Post(w, pullOpenedReq) responseContains(t, w, 200, "Processing...") if c.ExpAutoplanCommentFile != "" { + expNumTimesCalledCreateComment++ _, _, autoplanComment := vcsClient.VerifyWasCalledOnce().CreateComment(AnyRepo(), AnyInt(), AnyString()).GetCapturedArguments() assertCommentEquals(t, c.ExpAutoplanCommentFile, autoplanComment, c.RepoDir) } @@ -181,7 +183,12 @@ func TestGitHubWorkflow(t *testing.T) { w = httptest.NewRecorder() ctrl.Post(w, commentReq) responseContains(t, w, 200, "Processing...") - _, _, atlantisComment := vcsClient.VerifyWasCalled(Times((i/2)+2)).CreateComment(AnyRepo(), AnyInt(), AnyString()).GetCapturedArguments() + // Each comment warrants a response. The comments are at the + // even indices. + if i%2 == 0 { + expNumTimesCalledCreateComment++ + } + _, _, atlantisComment := vcsClient.VerifyWasCalled(Times(expNumTimesCalledCreateComment)).CreateComment(AnyRepo(), AnyInt(), AnyString()).GetCapturedArguments() assertCommentEquals(t, expOutputFile, atlantisComment, c.RepoDir) } @@ -190,8 +197,8 @@ func TestGitHubWorkflow(t *testing.T) { w = httptest.NewRecorder() ctrl.Post(w, pullClosedReq) responseContains(t, w, 200, "Pull request cleaned successfully") - numPrevComments := (len(c.CommentAndReplies) / 2) + 1 - _, _, pullClosedComment := vcsClient.VerifyWasCalled(Times(numPrevComments+1)).CreateComment(AnyRepo(), AnyInt(), AnyString()).GetCapturedArguments() + expNumTimesCalledCreateComment++ + _, _, pullClosedComment := vcsClient.VerifyWasCalled(Times(expNumTimesCalledCreateComment)).CreateComment(AnyRepo(), AnyInt(), AnyString()).GetCapturedArguments() assertCommentEquals(t, c.ExpMergeCommentFile, pullClosedComment, c.RepoDir) }) } diff --git a/server/testfixtures/test-repos/modules/exp-output-autoplan-only-modules.txt b/server/testfixtures/test-repos/modules/exp-output-autoplan-only-modules.txt deleted file mode 100644 index 63b09ca64..000000000 --- a/server/testfixtures/test-repos/modules/exp-output-autoplan-only-modules.txt +++ /dev/null @@ -1,2 +0,0 @@ -Ran `plan` in 0 projects because Atlantis detected no Terraform changes or could not determine where to run `plan`. -