Skip to content

Commit

Permalink
fix: report fails when there are no errors
Browse files Browse the repository at this point in the history
  • Loading branch information
mhrabovcin committed Feb 19, 2024
1 parent 5a4b986 commit 8a644d7
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions .github/actions/copacetic-action/pkg/patch/report.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,17 @@ func WriteMarkdown(report Report, w io.Writer) error {
Header: []string{"Image", "Patched", "Error"},
}

details := [][]string{}
errorDetails := [][]string{}

for i, row := range report {
mdRow := []string{
md.Code(row.Image),
md.Code(row.Patched),
}

if row.Error != "" {
mdRow = append(mdRow, md.Link("View error", fmt.Sprintf("#error-%d", i)))

detailsRow := []string{
row.Image,
fmt.Sprintf("error-%d", i),
Expand All @@ -69,23 +71,27 @@ func WriteMarkdown(report Report, w io.Writer) error {
if len(row.Output) > 0 {
detailsRow = append(detailsRow, row.Output)
}
details = append(details, detailsRow)

errorDetails = append(errorDetails, detailsRow)
} else {
mdRow = append(mdRow, "")
}

imagesTable.Rows = append(imagesTable.Rows, mdRow)
}

doc.H2("Patched images").LF().Table(imagesTable)

if len(details) > 0 {
if len(errorDetails) > 0 {
doc.H2("Errors")
}
for _, detail := range details {
for _, detail := range errorDetails {
doc.PlainText(fmt.Sprintf(`<a name="%s"></a>`, detail[1]))
content := []string{}
detailsContent := []string{}
for i := 2; i < len(detail); i++ {
content = append(content, fmt.Sprintf("<pre>%s</pre>", detail[i]))
detailsContent = append(detailsContent, fmt.Sprintf("<pre>%s</pre>", detail[i]))
}
doc.Details(detail[0], strings.Join(content, "\n"))
doc.Details(detail[0], strings.Join(detailsContent, "\n"))
}

return doc.Build()
Expand Down

0 comments on commit 8a644d7

Please sign in to comment.