Don't comment back on autoplan no projects.

This commit is contained in:
Luke Kysow
2018-07-16 17:24:29 +02:00
parent 7163ed586a
commit d11a927d7d
6 changed files with 47 additions and 22 deletions

View File

@@ -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

View File

@@ -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 {

View File

@@ -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<details><summary>Log</summary>\n <p>\n\n```\n{{.Log}}```\n</p></details>{{end}}\n"

View File

@@ -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,

View File

@@ -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)
})
}

View File

@@ -1,2 +0,0 @@
Ran `plan` in 0 projects because Atlantis detected no Terraform changes or could not determine where to run `plan`.