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

Add custom templates support (#2481) #2541

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
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
204 changes: 37 additions & 167 deletions server/events/markdown_renderer.go

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions server/events/templates/apply_unwrapped_success.tmpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{{ define "applyUnwrappedSuccess" -}}
```diff
{{.Output}}
```
{{- end }}
6 changes: 6 additions & 0 deletions server/events/templates/apply_wrapped_success.tmpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{{ define "applyWrappedSuccess" -}}
<details><summary>Show Output</summary>

{{ template "applyUnwrappedSuccess" . }}
</details>
{{- end }}
7 changes: 7 additions & 0 deletions server/events/templates/approve_all_projects.tmpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{{ define "approveAllProjects" -}}
Approved Policies for {{ len .Results }} projects:

{{ range $result := .Results }}1. {{ if $result.ProjectName }}project: `{{$result.ProjectName}}` {{ end }}dir: `{{$result.RepoRelDir}}` workspace: `{{$result.Workspace}}`
{{end}}
{{ template "log" . }}
{{ end }}
5 changes: 5 additions & 0 deletions server/events/templates/diverged.tmpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{{ define "diverged" -}}
{{ if .HasDiverged }}

:warning: The branch we're merging into is ahead, it is recommended to pull new commits first.{{end}}
{{- end }}
3 changes: 3 additions & 0 deletions server/events/templates/failure.tmpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{{ define "failure" -}}
**{{.Command}} Failed**: {{.Failure}}
{{- end }}
3 changes: 3 additions & 0 deletions server/events/templates/failure_with_log.tmpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{{ define "failureWithLog" -}}
{{ template "failure" . }}{{ template "log" . }}
{{ end }}
9 changes: 9 additions & 0 deletions server/events/templates/log.tmpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{{ define "log" -}}
{{if .Verbose}}
<details><summary>Log</summary>
<p>

```
{{.Log}}```
</p></details>{{end}}
{{- end }}
8 changes: 8 additions & 0 deletions server/events/templates/multi_project_apply.tmpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{{ define "multiProjectApply" -}}
{{ template "multiProjectHeader" . }}
{{ range $i, $result := .Results }}### {{add $i 1}}. {{ if $result.ProjectName }}project: `{{$result.ProjectName}}` {{ end }}dir: `{{$result.RepoRelDir}}` workspace: `{{$result.Workspace}}`
{{$result.Rendered}}

---
{{end}}{{ template "log" . }}
{{ end }}
6 changes: 6 additions & 0 deletions server/events/templates/multi_project_header.tmpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{{ define "multiProjectHeader" -}}
Ran {{.Command}} for {{ len .Results }} projects:

{{ range $result := .Results }}1. {{ if $result.ProjectName }}project: `{{$result.ProjectName}}` {{ end }}dir: `{{$result.RepoRelDir}}` workspace: `{{$result.Workspace}}`
{{end}}
{{- end }}
11 changes: 11 additions & 0 deletions server/events/templates/multi_project_plan.tmpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{{ define "multiProjectPlan" -}}
{{ template "multiProjectHeader" . }}
{{ $disableApplyAll := .DisableApplyAll }}{{ range $i, $result := .Results }}### {{add $i 1}}. {{ if $result.ProjectName }}project: `{{$result.ProjectName}}` {{ end }}dir: `{{$result.RepoRelDir}}` workspace: `{{$result.Workspace}}`
{{$result.Rendered}}

{{ if ne $disableApplyAll true }}---
{{end}}{{end}}{{ if ne .DisableApplyAll true }}{{ if and (gt (len .Results) 0) (not .PlansDeleted) }}* :fast_forward: To **apply** all unapplied plans from this pull request, comment:
* `atlantis apply`
* :put_litter_in_its_place: To delete all plans and locks for the PR, comment:
* `atlantis unlock`{{end}}{{end}}{{ template "log" . }}
{{ end }}
3 changes: 3 additions & 0 deletions server/events/templates/multi_project_version.tmpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{{ define "multiProjectVersion" -}}
{{ template "multiProjectApply" . }}
{{- end }}
11 changes: 11 additions & 0 deletions server/events/templates/plan_success_unwrapped.tmpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{{ define "planSuccessUnwrapped" -}}
```diff
{{ if .EnableDiffMarkdownFormat }}{{.DiffMarkdownFormattedTerraformOutput}}{{else}}{{.TerraformOutput}}{{end}}
```

{{ if .PlanWasDeleted }}This plan was not saved because one or more projects failed and automerge requires all plans pass.{{ else }}{{ if not .DisableApply }}* :arrow_forward: To **apply** this plan, comment:
* `{{.ApplyCmd}}`
{{end}}{{ if not .DisableRepoLocking }}* :put_litter_in_its_place: To **delete** this plan click [here]({{.LockURL}})
{{end}}* :repeat: To **plan** this project again, comment:
* `{{.RePlanCmd}}`{{end}}{{ template "diverged" . }}
{{- end }}
15 changes: 15 additions & 0 deletions server/events/templates/plan_success_wrapped.tmpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{{ define "planSuccessWrapped" -}}
<details><summary>Show Output</summary>

```diff
{{ if .EnableDiffMarkdownFormat }}{{.DiffMarkdownFormattedTerraformOutput}}{{else}}{{.TerraformOutput}}{{end}}
```

{{ if .PlanWasDeleted }}This plan was not saved because one or more projects failed and automerge requires all plans pass.{{ else }}{{ if not .DisableApply }}* :arrow_forward: To **apply** this plan, comment:
* `{{.ApplyCmd}}`
{{end}}{{ if not .DisableRepoLocking }}* :put_litter_in_its_place: To **delete** this plan click [here]({{.LockURL}})
{{end}}* :repeat: To **plan** this project again, comment:
* `{{.RePlanCmd}}`{{end}}
</details>
{{.PlanSummary}}{{ template "diverged" . }}
{{- end }}
11 changes: 11 additions & 0 deletions server/events/templates/policy_check_success_unwrapped.tmpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{{ define "policyCheckSuccessUnwrapped" -}}
```diff
{{.PolicyCheckOutput}}
```

* :arrow_forward: To **apply** this plan, comment:
* `{{.ApplyCmd}}`
* :put_litter_in_its_place: To **delete** this plan click [here]({{.LockURL}})
* :repeat: To re-run policies **plan** this project again by commenting:
* `{{.RePlanCmd}}`{{ template "diverged" . }}
{{- end }}
14 changes: 14 additions & 0 deletions server/events/templates/policy_check_success_wrapped.tmpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{{ define "policyCheckSuccessWrapped" -}}
<details><summary>Show Output</summary>

```diff
{{.PolicyCheckOutput}}
```

* :arrow_forward: To **apply** this plan, comment:
* `{{.ApplyCmd}}`
* :put_litter_in_its_place: To **delete** this plan click [here]({{.LockURL}})
* :repeat: To re-run policies **plan** this project again by commenting:
* `{{.RePlanCmd}}`
</details>{{ template "diverged" . }}
{{- end }}
6 changes: 6 additions & 0 deletions server/events/templates/single_project_apply.tmpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{{ define "singleProjectApply" -}}
{{$result := index .Results 0}}Ran {{.Command}} for {{ if $result.ProjectName }}project: `{{$result.ProjectName}}` {{ end }}dir: `{{$result.RepoRelDir}}` workspace: `{{$result.Workspace}}`

{{$result.Rendered}}
{{ template "log" . }}
{{ end }}
11 changes: 11 additions & 0 deletions server/events/templates/single_project_plan_success.tmpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{{ define "singleProjectPlanSuccess" -}}
{{$result := index .Results 0}}Ran {{.Command}} for {{ if $result.ProjectName }}project: `{{$result.ProjectName}}` {{ end }}dir: `{{$result.RepoRelDir}}` workspace: `{{$result.Workspace}}`

{{$result.Rendered}}

{{ if ne .DisableApplyAll true }}---
* :fast_forward: To **apply** all unapplied plans from this pull request, comment:
* `atlantis apply`
* :put_litter_in_its_place: To delete all plans and locks for the PR, comment:
* `atlantis unlock`{{ end }}{{ template "log" . }}
{{ end }}
6 changes: 6 additions & 0 deletions server/events/templates/single_project_plan_unsuccessful.tmpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{{ define "singleProjectPlanUnsuccessful" -}}
{{$result := index .Results 0}}Ran {{.Command}} for dir: `{{$result.RepoRelDir}}` workspace: `{{$result.Workspace}}`

{{$result.Rendered}}
{{ template "log" . }}
{{ end }}
6 changes: 6 additions & 0 deletions server/events/templates/single_project_version_success.tmpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{{ define "singleProjectVersionSuccess" -}}
{{$result := index .Results 0}}Ran {{.Command}} for {{ if $result.ProjectName }}project: `{{$result.ProjectName}}` {{ end }}dir: `{{$result.RepoRelDir}}` workspace: `{{$result.Workspace}}`

{{$result.Rendered}}
{{ template "log" . }}
{{ end }}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{{ define "singleProjectVersionUnsuccessful" -}}
{{ template "singleProjectPlanUnsuccessful" . }}
{{- end }}
10 changes: 10 additions & 0 deletions server/events/templates/unwrapped_err.tmpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{{ define "unwrappedErr" -}}
**{{.Command}} Error**
```
{{.Error}}
```{{ if eq .Command "Policy Check" }}
* :heavy_check_mark: To **approve** failing policies an authorized approver can comment:
* `atlantis approve_policies`
* :repeat: Or, address the policy failure by modifying the codebase and re-planning.
{{ end }}
{{- end }}
3 changes: 3 additions & 0 deletions server/events/templates/unwrapped_err_with_log.tmpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{{ define "unwrappedErrWithLog" -}}
{{ template "unwrappedErr" . }}{{ template "log" . }}
{{ end }}
5 changes: 5 additions & 0 deletions server/events/templates/version_unwrapped_success.tmpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{{ define "versionUnwrappedSuccess" -}}
```
{{.Output}}
```
{{ end }}
6 changes: 6 additions & 0 deletions server/events/templates/version_wrapped_success.tmpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{{ define "versionWrappedSuccess" -}}
<details><summary>Show Output</summary>

{{ template "versionUnwrappedSuccess" . }}
</details>
{{- end }}
9 changes: 9 additions & 0 deletions server/events/templates/wrapped_err.tmpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{{ define "wrappedErr" -}}
**{{.Command}} Error**
<details><summary>Show Output</summary>

```
{{.Error}}
```
</details>
{{- end }}