Skip to content

Commit

Permalink
fix: improve error printing
Browse files Browse the repository at this point in the history
  • Loading branch information
mhrabovcin committed Feb 19, 2024
1 parent 994fa1e commit 2252afe
Showing 1 changed file with 19 additions and 14 deletions.
33 changes: 19 additions & 14 deletions .github/actions/copacetic-action/pkg/patch/report.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"errors"
"fmt"
"io"
"strings"

md "github.com/go-spectest/markdown"

Expand Down Expand Up @@ -50,24 +49,30 @@ func WriteMarkdown(report Report, w io.Writer) error {
imagesTable := md.TableSet{
Header: []string{"Image", "Patched", "Error"},
}
for _, row := range report {

details := [][]string{}

for i, row := range report {
mdRow := []string{
row.Image,
row.Patched,
row.Error,
md.Code(row.Image),
md.Code(row.Patched),
}
for i := range mdRow {
if len(mdRow[i]) > 0 {
mdRow[i] = codeForTable(mdRow[i])
}
if row.Error != "" {
mdRow = append(mdRow, md.Link("View error", fmt.Sprintf("#error-%d", i)))
details = append(details, []string{
row.Image,
row.Error,
row.Output,
})
}
imagesTable.Rows = append(imagesTable.Rows, mdRow)
}

doc.H2("Patched images").PlainText("").Table(imagesTable)
return doc.Build()
}
doc.H2("Patched images").LF().Table(imagesTable)

for _, detail := range details {
doc.Details(detail[0], fmt.Sprintf("```%s```", detail[1]))
}

func codeForTable(s string) string {
return fmt.Sprintf("<pre>%s</pre>", strings.ReplaceAll(s, "\n", "<br/>"))
return doc.Build()
}

0 comments on commit 2252afe

Please sign in to comment.