Documentation
¶
Overview ¶
Package covreport turns Go coverage profiles into a per-file Markdown table for the PR coverage comment (see .github/workflows/coverage.yml).
Go's `go tool cover -func` reports per-function statement coverage and an aggregate total, but not a per-file covered/total breakdown. This package parses the raw profile itself — summing statement counts per file — so the coverage comment can show which files have the most untested code (sorted by uncovered statement count, most first, the most actionable) with a delta measured against the PR base.
Coverage in Go is statement-based, not line-based, so the counts here are statements. The rendered table labels them accordingly rather than claiming "lines".
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ModulePath ¶
ModulePath reads the module path from a go.mod file (the token after the leading `module` directive). It is best-effort: on any read error or a file without a module line it returns an empty string, which makes Parse leave import paths unstripped rather than fail the whole report.
func Parse ¶
Parse reads a Go coverage profile and returns per-file statement counts keyed by repo-relative path. The module prefix (from go.mod) is stripped from the profile's import-path-qualified file names so the table shows repo-relative paths. The leading "mode:" line and blank lines are skipped.
Profile block lines have the form:
<import-path>/file.go:startLine.startCol,endLine.endCol numStatements count
A block counts toward Covered when its execution count is non-zero.
func RenderTable ¶
RenderTable renders rows as a GitHub-flavoured Markdown table. When baseAvailable is false (the base commit failed to build/test) the delta column is filled with "—" rather than misleading per-file deltas; when it is true, a file absent from the base shows "new". With no rows it returns a short italic placeholder so the caller can still embed something meaningful.
Types ¶
type FileCov ¶
type FileCov struct {
Path string // repo-relative path, e.g. internal/daemon/handler.go
Covered int
Total int
}
FileCov accumulates covered and total statement counts for one file.
type Row ¶
type Row struct {
Path string
Pct float64
Covered int
Total int
Delta float64 // Pct(head) - Pct(base); meaningful only when InBase
InBase bool // false => new file (no base measurement)
}
Row is one file's line in the rendered table, including its delta against the base branch.
func BuildRows ¶
BuildRows joins head and base per-file coverage into table rows, sorted by most uncovered statements first (ties broken by path for stable output). Ordering by absolute uncovered statement count — not coverage percentage — surfaces the files where writing tests buys the most: a 90%-covered 500-statement file has more untested code (and more risk) than a 50%-covered 4-statement file, yet a percentage sort would bury it. Only files present in head are listed — a file that existed at base but was deleted in the PR no longer has coverage to report.