Skip to content

Commit

Permalink
Merge pull request #284 from k1LoW/fix-custom-metrics-report
Browse files Browse the repository at this point in the history
  • Loading branch information
k1LoW authored Oct 2, 2023
2 parents 0074594 + 5ccfbf2 commit 0dc075c
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion report/custom.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,9 @@ func (s *CustomMetricSet) Out(w io.Writer) error {
return nil
}
table := tablewriter.NewWriter(w)
if s.Name == "" {
s.Name = s.Key
}
table.SetHeader([]string{s.Name, makeHeadTitle(s.report.Ref, s.report.Commit, s.report.covPaths)})
table.SetHeaderColor(tablewriter.Colors{tablewriter.Bold}, tablewriter.Colors{})
table.SetAutoFormatHeaders(false)
Expand All @@ -130,6 +133,9 @@ func (s *CustomMetricSet) Out(w io.Writer) error {
table.SetColumnAlignment([]int{tablewriter.ALIGN_LEFT, tablewriter.ALIGN_RIGHT})

for _, m := range s.Metrics {
if m.Name == "" {
m.Name = m.Key
}
var v string
if isInt(m.Value) {
v = fmt.Sprintf("%d%s", int(m.Value), m.Unit)
Expand Down Expand Up @@ -232,6 +238,9 @@ func (d *DiffCustomMetricSet) Table() string {
return d.A.Table()
}
buf := new(bytes.Buffer)
if d.Name == "" {
d.Name = d.Key
}
_, _ = buf.WriteString(fmt.Sprintf("## %s\n\n", d.Name)) //nostyle:handlerrors
table := tablewriter.NewWriter(buf)
table.SetAutoFormatHeaders(false)
Expand Down Expand Up @@ -272,6 +281,9 @@ func (d *DiffCustomMetricSet) Table() string {
vb = fmt.Sprintf("%.1f%s", *m.B, m.customMetricB.Unit)
diff = fmt.Sprintf("%.1f%s", m.Diff, m.customMetricA.Unit)
}
if m.Name == "" {
m.Name = m.Key
}
table.Append([]string{fmt.Sprintf("**%s**", m.Name), vb, va, diff})
}
table.Render()
Expand Down Expand Up @@ -301,7 +313,10 @@ func (d *DiffCustomMetricSet) MetadataTable() string {
if !ok {
mb = &MetadataKV{}
}
table.Append([]string{fmt.Sprintf("**%s**", ma.Key), mb.Value, ma.Value})
if ma.Name == "" {
ma.Name = ma.Key
}
table.Append([]string{fmt.Sprintf("**%s**", ma.Name), mb.Value, ma.Value})
}
table.Render()
buf.WriteString("\n</details>\n")
Expand Down

0 comments on commit 0dc075c

Please sign in to comment.