Skip to content

Commit 4793549

Browse files
authored
feat/plan summary in collapsible (#1671)
* Make plan summary in its own collapsible comment
1 parent c473931 commit 4793549

File tree

2 files changed

+25
-7
lines changed

2 files changed

+25
-7
lines changed

cli/pkg/digger/digger.go

+16-4
Original file line numberDiff line numberDiff line change
@@ -319,10 +319,7 @@ func run(command string, job orchestrator.Job, policyChecker policy.Checker, org
319319
if err != nil {
320320
log.Printf("Failed to report plan. %v", err)
321321
}
322-
_, _, err = reporter.Report("\n"+planSummary, coreutils.AsComment("Terraform plan summary"))
323-
if err != nil {
324-
log.Printf("Failed to report summary of plan. %v", err)
325-
}
322+
reportPlanSummary(reporter, planSummary)
326323
}
327324
} else {
328325
reportEmptyPlanOutput(reporter, projectLock.LockId())
@@ -517,6 +514,21 @@ func reportTerraformPlanOutput(reporter reporting.Reporter, projectId string, pl
517514
}
518515
}
519516

517+
func reportPlanSummary(reporter reporting.Reporter, summary string) {
518+
var formatter func(string) string
519+
520+
if reporter.SupportsMarkdown() {
521+
formatter = coreutils.AsCollapsibleComment("Plan summary", false)
522+
} else {
523+
formatter = coreutils.AsComment("Plan summary")
524+
}
525+
526+
_, _, err := reporter.Report("\n"+summary, formatter)
527+
if err != nil {
528+
log.Printf("Failed to report plan summary. %v", err)
529+
}
530+
}
531+
520532
func reportEmptyPlanOutput(reporter reporting.Reporter, projectId string) {
521533
identityFormatter := func(comment string) string {
522534
return comment

libs/comment_utils/utils/comments.go

+9-3
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,16 @@ func GetTerraformOutputAsComment(summary string) func(string) string {
2727
}
2828

2929
func AsCollapsibleComment(summary string, open bool) func(string) string {
30+
var openTag string
31+
if open {
32+
openTag = "open=\"true\""
33+
} else {
34+
openTag = ""
35+
}
3036
return func(comment string) string {
31-
return fmt.Sprintf(`<details><summary>` + summary + `</summary>
32-
` + comment + `
33-
</details>`)
37+
return fmt.Sprintf(`<details %v><summary>`+summary+`</summary>
38+
`+comment+`
39+
</details>`, openTag)
3440
}
3541
}
3642

0 commit comments

Comments
 (0)