@@ -44,17 +44,19 @@ type MarkdownRenderer struct {
44
44
DisableApply bool
45
45
DisableMarkdownFolding bool
46
46
DisableRepoLocking bool
47
+ EnableDiffMarkdownFormat bool
47
48
}
48
49
49
50
// commonData is data that all responses have.
50
51
type commonData struct {
51
- Command string
52
- Verbose bool
53
- Log string
54
- PlansDeleted bool
55
- DisableApplyAll bool
56
- DisableApply bool
57
- DisableRepoLocking bool
52
+ Command string
53
+ Verbose bool
54
+ Log string
55
+ PlansDeleted bool
56
+ DisableApplyAll bool
57
+ DisableApply bool
58
+ DisableRepoLocking bool
59
+ EnableDiffMarkdownFormat bool
58
60
}
59
61
60
62
// errData is data about an error response.
@@ -77,10 +79,11 @@ type resultData struct {
77
79
78
80
type planSuccessData struct {
79
81
models.PlanSuccess
80
- PlanSummary string
81
- PlanWasDeleted bool
82
- DisableApply bool
83
- DisableRepoLocking bool
82
+ PlanSummary string
83
+ PlanWasDeleted bool
84
+ DisableApply bool
85
+ DisableRepoLocking bool
86
+ EnableDiffMarkdownFormat bool
84
87
}
85
88
86
89
type policyCheckSuccessData struct {
@@ -99,13 +102,14 @@ type projectResultTmplData struct {
99
102
func (m * MarkdownRenderer ) Render (res CommandResult , cmdName models.CommandName , log string , verbose bool , vcsHost models.VCSHostType ) string {
100
103
commandStr := strings .Title (strings .Replace (cmdName .String (), "_" , " " , - 1 ))
101
104
common := commonData {
102
- Command : commandStr ,
103
- Verbose : verbose ,
104
- Log : log ,
105
- PlansDeleted : res .PlansDeleted ,
106
- DisableApplyAll : m .DisableApplyAll || m .DisableApply ,
107
- DisableApply : m .DisableApply ,
108
- DisableRepoLocking : m .DisableRepoLocking ,
105
+ Command : commandStr ,
106
+ Verbose : verbose ,
107
+ Log : log ,
108
+ PlansDeleted : res .PlansDeleted ,
109
+ DisableApplyAll : m .DisableApplyAll || m .DisableApply ,
110
+ DisableApply : m .DisableApply ,
111
+ DisableRepoLocking : m .DisableRepoLocking ,
112
+ EnableDiffMarkdownFormat : m .EnableDiffMarkdownFormat ,
109
113
}
110
114
if res .Error != nil {
111
115
return m .renderTemplate (unwrappedErrWithLogTmpl , errData {res .Error .Error (), common })
@@ -150,9 +154,9 @@ func (m *MarkdownRenderer) renderProjectResults(results []models.ProjectResult,
150
154
})
151
155
} else if result .PlanSuccess != nil {
152
156
if m .shouldUseWrappedTmpl (vcsHost , result .PlanSuccess .TerraformOutput ) {
153
- resultData .Rendered = m .renderTemplate (planSuccessWrappedTmpl , planSuccessData {PlanSuccess : * result .PlanSuccess , PlanSummary : result .PlanSuccess .Summary (), PlanWasDeleted : common .PlansDeleted , DisableApply : common .DisableApply , DisableRepoLocking : common .DisableRepoLocking })
157
+ resultData .Rendered = m .renderTemplate (planSuccessWrappedTmpl , planSuccessData {PlanSuccess : * result .PlanSuccess , PlanSummary : result .PlanSuccess .Summary (), PlanWasDeleted : common .PlansDeleted , DisableApply : common .DisableApply , DisableRepoLocking : common .DisableRepoLocking , EnableDiffMarkdownFormat : common . EnableDiffMarkdownFormat })
154
158
} else {
155
- resultData .Rendered = m .renderTemplate (planSuccessUnwrappedTmpl , planSuccessData {PlanSuccess : * result .PlanSuccess , PlanWasDeleted : common .PlansDeleted , DisableApply : common .DisableApply , DisableRepoLocking : common .DisableRepoLocking })
159
+ resultData .Rendered = m .renderTemplate (planSuccessUnwrappedTmpl , planSuccessData {PlanSuccess : * result .PlanSuccess , PlanWasDeleted : common .PlansDeleted , DisableApply : common .DisableApply , DisableRepoLocking : common .DisableRepoLocking , EnableDiffMarkdownFormat : common . EnableDiffMarkdownFormat })
156
160
}
157
161
numPlanSuccesses ++
158
162
} else if result .PolicyCheckSuccess != nil {
@@ -300,14 +304,14 @@ var multiProjectVersionTmpl = template.Must(template.New("").Funcs(sprig.TxtFunc
300
304
logTmpl ))
301
305
var planSuccessUnwrappedTmpl = template .Must (template .New ("" ).Parse (
302
306
"```diff\n " +
303
- "{{. TerraformOutput}}\n " +
307
+ "{{ if .EnableDiffMarkdownFormat }}{{.DiffMarkdownFormattedTerraformOutput}}{{else}}{{. TerraformOutput}}{{end }}\n " +
304
308
"```\n \n " + planNextSteps +
305
309
"{{ if .HasDiverged }}\n \n :warning: The branch we're merging into is ahead, it is recommended to pull new commits first.{{end}}" ))
306
310
307
311
var planSuccessWrappedTmpl = template .Must (template .New ("" ).Parse (
308
312
"<details><summary>Show Output</summary>\n \n " +
309
313
"```diff\n " +
310
- "{{. TerraformOutput}}\n " +
314
+ "{{ if .EnableDiffMarkdownFormat }}{{.DiffMarkdownFormattedTerraformOutput}}{{else}}{{. TerraformOutput}}{{end }}\n " +
311
315
"```\n \n " +
312
316
planNextSteps + "\n " +
313
317
"</details>" + "\n " +
0 commit comments