diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 5d2df8db..4ec9b8b6 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -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: | diff --git a/cmd/comment.go b/cmd/comment.go index 2e657ca2..5022795e 100644 --- a/cmd/comment.go +++ b/cmd/comment.go @@ -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) diff --git a/report/custom.go b/report/custom.go index 579a4375..6ba255f3 100644 --- a/report/custom.go +++ b/report/custom.go @@ -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) +}