Merge pull request #293 from runatlantis/fix-output

Fix multi-project output.
This commit is contained in:
Luke Kysow
2018-09-28 11:08:35 -05:00
committed by GitHub
16 changed files with 132 additions and 31 deletions

View File

@@ -204,7 +204,7 @@ var multiProjectPlanTmpl = template.Must(template.New("").Funcs(sprig.TxtFuncMap
"{{end}}\n" +
"{{ range $i, $result := .Results }}" +
"### {{add $i 1}}. workspace: `{{$result.Workspace}}` dir: `{{$result.RepoRelDir}}`\n" +
"{{$result.Rendered}}\n" +
"{{$result.Rendered}}\n\n" +
"---\n{{end}}{{ if gt (len .Results) 0 }}* :fast_forward: To **apply** all unapplied plans from this pull request, comment:\n" +
" * `atlantis apply`{{end}}" +
logTmpl))
@@ -215,7 +215,7 @@ var multiProjectApplyTmpl = template.Must(template.New("").Funcs(sprig.TxtFuncMa
"{{end}}\n" +
"{{ range $i, $result := .Results }}" +
"### {{add $i 1}}. workspace: `{{$result.Workspace}}` dir: `{{$result.RepoRelDir}}`\n" +
"{{$result.Rendered}}\n" +
"{{$result.Rendered}}\n\n" +
"---\n{{end}}" +
logTmpl))
var planSuccessUnwrappedTmpl = template.Must(template.New("").Parse(
@@ -227,7 +227,7 @@ var planSuccessWrappedTmpl = template.Must(template.New("").Parse(
"```diff\n" +
"{{.TerraformOutput}}\n" +
"```\n\n" +
planNextSteps +
planNextSteps + "\n" +
"</details>"))
// planNextSteps are instructions appended after successful plans as to what
@@ -250,7 +250,7 @@ var applyWrappedSuccessTmpl = template.Must(template.New("").Parse(
var unwrappedErrTmplText = "**{{.Command}} Error**\n" +
"```\n" +
"{{.Error}}\n" +
"```\n"
"```"
var wrappedErrTmplText = "**{{.Command}} Error**\n" +
"<details><summary>Show Output</summary>\n\n" +
"```\n" +
@@ -259,7 +259,7 @@ var wrappedErrTmplText = "**{{.Command}} Error**\n" +
var unwrappedErrTmpl = template.Must(template.New("").Parse(unwrappedErrTmplText))
var unwrappedErrWithLogTmpl = template.Must(template.New("").Parse(unwrappedErrTmplText + logTmpl))
var wrappedErrTmpl = template.Must(template.New("").Parse(wrappedErrTmplText))
var failureTmplText = "**{{.Command}} Failed**: {{.Failure}}\n"
var failureTmplText = "**{{.Command}} Failed**: {{.Failure}}"
var failureTmpl = template.Must(template.New("").Parse(failureTmplText))
var failureWithLogTmpl = template.Must(template.New("").Parse(failureTmplText + logTmpl))
var logTmpl = "{{if .Verbose}}\n<details><summary>Log</summary>\n <p>\n\n```\n{{.Log}}```\n</p></details>{{end}}\n"

View File

@@ -36,13 +36,13 @@ func TestRenderErr(t *testing.T) {
"apply error",
events.ApplyCommand,
err,
"**Apply Error**\n```\nerr\n```\n\n",
"**Apply Error**\n```\nerr\n```\n",
},
{
"plan error",
events.PlanCommand,
err,
"**Plan Error**\n```\nerr\n```\n\n",
"**Plan Error**\n```\nerr\n```\n",
},
}
@@ -76,13 +76,13 @@ func TestRenderFailure(t *testing.T) {
"apply failure",
events.ApplyCommand,
"failure",
"**Apply Failed**: failure\n\n",
"**Apply Failed**: failure\n",
},
{
"plan failure",
events.PlanCommand,
"failure",
"**Plan Failed**: failure\n\n",
"**Plan Failed**: failure\n",
},
}
@@ -113,7 +113,7 @@ func TestRenderErrAndFailure(t *testing.T) {
Failure: "failure",
}
s := r.Render(res, events.PlanCommand, "", false, models.Github)
Equals(t, "**Plan Error**\n```\nerror\n```\n\n", s)
Equals(t, "**Plan Error**\n```\nerror\n```\n", s)
}
func TestRenderProjectResults(t *testing.T) {
@@ -223,6 +223,7 @@ $$$
* :put_litter_in_its_place: To **delete** this plan click [here](lock-url)
* :repeat: To **plan** this project again, comment:
* $atlantis plan -d path -w workspace$
---
### 2. workspace: $workspace$ dir: $path2$
$$$diff
@@ -234,6 +235,7 @@ $$$
* :put_litter_in_its_place: To **delete** this plan click [here](lock-url2)
* :repeat: To **plan** this project again, comment:
* $atlantis plan -d path2 -w workspace$
---
* :fast_forward: To **apply** all unapplied plans from this pull request, comment:
* $atlantis apply$
@@ -263,11 +265,13 @@ $$$
$$$diff
success
$$$
---
### 2. workspace: $workspace$ dir: $path2$
$$$diff
success2
$$$
---
`,
@@ -290,7 +294,6 @@ $$$
error
$$$
`,
},
{
@@ -308,7 +311,6 @@ $$$
**Plan Failed**: failure
`,
},
{
@@ -352,6 +354,7 @@ $$$
* :put_litter_in_its_place: To **delete** this plan click [here](lock-url)
* :repeat: To **plan** this project again, comment:
* $atlantis plan -d path -w workspace$
---
### 2. workspace: $workspace$ dir: $path2$
**Plan Failed**: failure
@@ -398,6 +401,7 @@ $$$
$$$diff
success
$$$
---
### 2. workspace: $workspace$ dir: $path2$
**Apply Failed**: failure
@@ -443,6 +447,7 @@ $$$
$$$diff
success
$$$
---
### 2. workspace: $workspace$ dir: $path2$
**Apply Failed**: failure
@@ -568,7 +573,8 @@ $$$
* $atlantis apply -d .$
* :put_litter_in_its_place: To **delete** this plan click [here](lock-url)
* :repeat: To **plan** this project again, comment:
* $atlantis plan -d .$</details>
* $atlantis plan -d .$
</details>
---
* :fast_forward: To **apply** all unapplied plans from this pull request, comment:
@@ -662,7 +668,6 @@ $$$
` + c.Output + `
$$$
`
}
@@ -768,7 +773,8 @@ $$$
* $applycmd$
* :put_litter_in_its_place: To **delete** this plan click [here](lock-url)
* :repeat: To **plan** this project again, comment:
* $replancmd$</details>
* $replancmd$
</details>
---
* :fast_forward: To **apply** all unapplied plans from this pull request, comment:
@@ -822,7 +828,7 @@ $$$
}
}
func TestRenderProjectResults_MultiProjectWrapped(t *testing.T) {
func TestRenderProjectResults_MultiProjectApplyWrapped(t *testing.T) {
mr := events.MarkdownRenderer{}
tfOut := strings.Repeat("line\n", 13)
rendered := mr.Render(events.CommandResult{
@@ -850,6 +856,7 @@ $$$diff
` + tfOut + `
$$$
</details>
---
### 2. workspace: $production$ dir: $.$
<details><summary>Show Output</summary>
@@ -858,9 +865,78 @@ $$$diff
` + tfOut + `
$$$
</details>
---
`
expWithBackticks := strings.Replace(exp, "$", "`", -1)
Equals(t, expWithBackticks, rendered)
}
func TestRenderProjectResults_MultiProjectPlanWrapped(t *testing.T) {
mr := events.MarkdownRenderer{}
tfOut := strings.Repeat("line\n", 13)
rendered := mr.Render(events.CommandResult{
ProjectResults: []events.ProjectResult{
{
RepoRelDir: ".",
Workspace: "staging",
PlanSuccess: &events.PlanSuccess{
TerraformOutput: tfOut,
LockURL: "staging-lock-url",
ApplyCmd: "staging-apply-cmd",
RePlanCmd: "staging-replan-cmd",
},
},
{
RepoRelDir: ".",
Workspace: "production",
PlanSuccess: &events.PlanSuccess{
TerraformOutput: tfOut,
LockURL: "production-lock-url",
ApplyCmd: "production-apply-cmd",
RePlanCmd: "production-replan-cmd",
},
},
},
}, events.PlanCommand, "log", false, models.Github)
exp := `Ran Plan for 2 projects:
1. workspace: $staging$ dir: $.$
1. workspace: $production$ dir: $.$
### 1. workspace: $staging$ dir: $.$
<details><summary>Show Output</summary>
$$$diff
` + tfOut + `
$$$
* :arrow_forward: To **apply** this plan, comment:
* $staging-apply-cmd$
* :put_litter_in_its_place: To **delete** this plan click [here](staging-lock-url)
* :repeat: To **plan** this project again, comment:
* $staging-replan-cmd$
</details>
---
### 2. workspace: $production$ dir: $.$
<details><summary>Show Output</summary>
$$$diff
` + tfOut + `
$$$
* :arrow_forward: To **apply** this plan, comment:
* $production-apply-cmd$
* :put_litter_in_its_place: To **delete** this plan click [here](production-lock-url)
* :repeat: To **plan** this project again, comment:
* $production-replan-cmd$
</details>
---
* :fast_forward: To **apply** all unapplied plans from this pull request, comment:
* $atlantis apply$
`
expWithBackticks := strings.Replace(exp, "$", "`", -1)
Equals(t, expWithBackticks, rendered)
}

View File

@@ -29,7 +29,9 @@ Plan: 1 to add, 0 to change, 0 to destroy.
* `atlantis apply -d staging`
* :put_litter_in_its_place: To **delete** this plan click [here](lock-url)
* :repeat: To **plan** this project again, comment:
* `atlantis plan -d staging`</details>
* `atlantis plan -d staging`
</details>
---
### 2. workspace: `default` dir: `production`
<details><summary>Show Output</summary>
@@ -58,7 +60,9 @@ Plan: 1 to add, 0 to change, 0 to destroy.
* `atlantis apply -d production`
* :put_litter_in_its_place: To **delete** this plan click [here](lock-url)
* :repeat: To **plan** this project again, comment:
* `atlantis plan -d production`</details>
* `atlantis plan -d production`
</details>
---
* :fast_forward: To **apply** all unapplied plans from this pull request, comment:
* `atlantis apply`

View File

@@ -26,7 +26,8 @@ Plan: 1 to add, 0 to change, 0 to destroy.
* `atlantis apply -d staging`
* :put_litter_in_its_place: To **delete** this plan click [here](lock-url)
* :repeat: To **plan** this project again, comment:
* `atlantis plan -d staging`</details>
* `atlantis plan -d staging`
</details>
---
* :fast_forward: To **apply** all unapplied plans from this pull request, comment:

View File

@@ -26,7 +26,8 @@ Plan: 1 to add, 0 to change, 0 to destroy.
* `atlantis apply -d production`
* :put_litter_in_its_place: To **delete** this plan click [here](lock-url)
* :repeat: To **plan** this project again, comment:
* `atlantis plan -d production`</details>
* `atlantis plan -d production`
</details>
---
* :fast_forward: To **apply** all unapplied plans from this pull request, comment:

View File

@@ -26,7 +26,8 @@ Plan: 1 to add, 0 to change, 0 to destroy.
* `atlantis apply -d staging`
* :put_litter_in_its_place: To **delete** this plan click [here](lock-url)
* :repeat: To **plan** this project again, comment:
* `atlantis plan -d staging`</details>
* `atlantis plan -d staging`
</details>
---
* :fast_forward: To **apply** all unapplied plans from this pull request, comment:

View File

@@ -15,6 +15,7 @@ var = fromconfig
workspace = default
```
---
### 2. workspace: `staging` dir: `.`
```diff
@@ -29,5 +30,6 @@ var = fromfile
workspace = staging
```
---

View File

@@ -29,7 +29,9 @@ Plan: 1 to add, 0 to change, 0 to destroy.
* `atlantis apply -d .`
* :put_litter_in_its_place: To **delete** this plan click [here](lock-url)
* :repeat: To **plan** this project again, comment:
* `atlantis plan -d .`</details>
* `atlantis plan -d .`
</details>
---
### 2. workspace: `staging` dir: `.`
<details><summary>Show Output</summary>
@@ -58,7 +60,9 @@ Plan: 1 to add, 0 to change, 0 to destroy.
* `atlantis apply -w staging`
* :put_litter_in_its_place: To **delete** this plan click [here](lock-url)
* :repeat: To **plan** this project again, comment:
* `atlantis plan -w staging`</details>
* `atlantis plan -w staging`
</details>
---
* :fast_forward: To **apply** all unapplied plans from this pull request, comment:
* `atlantis apply`

View File

@@ -15,6 +15,7 @@ var = default_workspace
workspace = default
```
---
### 2. workspace: `new_workspace` dir: `.`
```diff
@@ -29,5 +30,6 @@ var = new_workspace
workspace = new_workspace
```
---

View File

@@ -26,7 +26,8 @@ Plan: 1 to add, 0 to change, 0 to destroy.
* `atlantis apply -w new_workspace`
* :put_litter_in_its_place: To **delete** this plan click [here](lock-url)
* :repeat: To **plan** this project again, comment:
* `atlantis plan -w new_workspace -- -var var=new_workspace`</details>
* `atlantis plan -w new_workspace -- -var var=new_workspace`
</details>
---
* :fast_forward: To **apply** all unapplied plans from this pull request, comment:

View File

@@ -26,7 +26,8 @@ Plan: 1 to add, 0 to change, 0 to destroy.
* `atlantis apply -d .`
* :put_litter_in_its_place: To **delete** this plan click [here](lock-url)
* :repeat: To **plan** this project again, comment:
* `atlantis plan -d . -- -var var=overridden`</details>
* `atlantis plan -d . -- -var var=overridden`
</details>
---
* :fast_forward: To **apply** all unapplied plans from this pull request, comment:

View File

@@ -26,7 +26,8 @@ Plan: 1 to add, 0 to change, 0 to destroy.
* `atlantis apply -d .`
* :put_litter_in_its_place: To **delete** this plan click [here](lock-url)
* :repeat: To **plan** this project again, comment:
* `atlantis plan -d . -- -var var=default_workspace`</details>
* `atlantis plan -d . -- -var var=default_workspace`
</details>
---
* :fast_forward: To **apply** all unapplied plans from this pull request, comment:

View File

@@ -26,7 +26,8 @@ Plan: 1 to add, 0 to change, 0 to destroy.
* `atlantis apply -d .`
* :put_litter_in_its_place: To **delete** this plan click [here](lock-url)
* :repeat: To **plan** this project again, comment:
* `atlantis plan -d .`</details>
* `atlantis plan -d .`
</details>
---
* :fast_forward: To **apply** all unapplied plans from this pull request, comment:

View File

@@ -26,7 +26,8 @@ Plan: 1 to add, 0 to change, 0 to destroy.
* `atlantis apply -p default`
* :put_litter_in_its_place: To **delete** this plan click [here](lock-url)
* :repeat: To **plan** this project again, comment:
* `atlantis plan -p default`</details>
* `atlantis plan -p default`
</details>
---
* :fast_forward: To **apply** all unapplied plans from this pull request, comment:

View File

@@ -26,7 +26,8 @@ Plan: 1 to add, 0 to change, 0 to destroy.
* `atlantis apply -p staging`
* :put_litter_in_its_place: To **delete** this plan click [here](lock-url)
* :repeat: To **plan** this project again, comment:
* `atlantis plan -p staging`</details>
* `atlantis plan -p staging`
</details>
---
* :fast_forward: To **apply** all unapplied plans from this pull request, comment:

View File

@@ -31,7 +31,9 @@ workspace=default
* `atlantis apply -p default`
* :put_litter_in_its_place: To **delete** this plan click [here](lock-url)
* :repeat: To **plan** this project again, comment:
* `atlantis plan -p default`</details>
* `atlantis plan -p default`
</details>
---
### 2. workspace: `default` dir: `.`
<details><summary>Show Output</summary>
@@ -60,7 +62,9 @@ Plan: 1 to add, 0 to change, 0 to destroy.
* `atlantis apply -p staging`
* :put_litter_in_its_place: To **delete** this plan click [here](lock-url)
* :repeat: To **plan** this project again, comment:
* `atlantis plan -p staging`</details>
* `atlantis plan -p staging`
</details>
---
* :fast_forward: To **apply** all unapplied plans from this pull request, comment:
* `atlantis apply`