Skip to content

Commit

Permalink
Show custom metrics in pull request comments
Browse files Browse the repository at this point in the history
  • Loading branch information
k1LoW committed Sep 1, 2023
1 parent 8ef0614 commit bbc3bee
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 0 deletions.
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ jobs:
uses: ./testdata/actions/coverage
env:
MACKEREL_API_KEY: ${{ secrets.MACKEREL_API_KEY }}
OCTOCOV_CUSTOM_METRICS_BENCHMARK_0: ./testdata/custom_metrics/benchmark_0.json

- name: Show rate limit
run: |
Expand Down
3 changes: 3 additions & 0 deletions cmd/comment.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@ func createReportContent(ctx context.Context, c *config.Config, r, rPrev *report
d := r.Compare(rPrev)
table = d.Table()
fileTable = d.FileCoveagesTable(files)
for _, s := range d.CustomMetrics {
customTables = append(customTables, s.Table())
}
} else {
table = r.Table()
fileTable = r.FileCoveagesTable(files)
Expand Down
21 changes: 21 additions & 0 deletions report/custom.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,3 +133,24 @@ func (m *CustomMetric) Compare(m2 *CustomMetric) *DiffCustomMetric {

return d
}

func (d *DiffCustomMetricSet) Table() string {
if len(d.Metrics) == 0 {
return ""
}
buf := new(bytes.Buffer)
_, _ = buf.WriteString(fmt.Sprintf("## %s\n\n", d.Name))
table := tablewriter.NewWriter(buf)
table.SetAutoFormatHeaders(false)
table.SetAutoWrapText(false)
table.SetBorders(tablewriter.Border{Left: true, Top: false, Right: true, Bottom: false})
table.SetCenterSeparator("|")
table.SetColumnAlignment([]int{tablewriter.ALIGN_LEFT, tablewriter.ALIGN_RIGHT, tablewriter.ALIGN_RIGHT, tablewriter.ALIGN_RIGHT})

table.SetHeader([]string{"", makeHeadTitleWithLink(d.reportB.Ref, d.reportB.Commit, nil), makeHeadTitleWithLink(d.reportA.Ref, d.reportA.Commit, nil), "+/-"})
for _, metric := range d.Metrics {
table.Append([]string{metric.Name, fmt.Sprintf("%.1f%s", *metric.B, metric.customMetricB.Unit), fmt.Sprintf("%.1f%s", *metric.A, metric.customMetricA.Unit), fmt.Sprintf("%.1f%s", metric.Diff, metric.customMetricA.Unit)})
}
table.Render()
return strings.Replace(strings.Replace(buf.String(), "---|", "--:|", 4), "--:|", "---|", 1)
}

0 comments on commit bbc3bee

Please sign in to comment.