report

package
v0.1.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 13, 2026 License: GPL-3.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CompressUncoveredLines

func CompressUncoveredLines(w io.Writer, ull []int)

CompressUncoveredLines writes uncovered line ranges in compressed format (e.g., "1-3 5 7").

func Deliver

func Deliver(w io.Writer, output string, cfg OutputConfig)

Deliver routes formatted output to its target based on config.

func SetGithubActionOutput

func SetGithubActionOutput(totalCoveragePercent int, bestReport string) error

SetGithubActionOutput writes total coverage and report to the GITHUB_OUTPUT file.

Types

type BuildInput

type BuildInput struct {
	Pass                         bool
	PassCoverage                 bool
	TotalStats                   coverage.Stats
	FileThreshold                int
	PackageThreshold             int
	HasFileOverrides             bool
	HasPackageOverrides          bool
	FilesBelowThreshold          []coverage.Stats
	PackagesBelowThreshold       []coverage.Stats
	FilesWithUncoveredLines      []coverage.Stats
	FilesWithMissingExplanations []coverage.Stats
	HasBaseBreakdown             bool
	DiffThreshold                *float64
	MeetsDiffThreshold           bool
	DiffPercentage               float64
	Diff                         []coverage.FileCoverageDiff
}

BuildInput contains all the data needed to build a report. This replaces the direct dependency on check.AnalyzeResult.

type CSVFormatter

type CSVFormatter struct{}

CSVFormatter produces CSV output with multi-section layout. Each section starts with a `# Comment` line, followed by a CSV header and data rows. Sections are separated by blank lines.

func (*CSVFormatter) Format

func (f *CSVFormatter) Format(r Report) string

type CoverageSection

type CoverageSection struct {
	Threshold      int              `json:"threshold"`
	HasOverrides   bool             `json:"hasOverrides,omitempty"`
	Pass           bool             `json:"pass"`
	BelowThreshold []coverage.Stats `json:"belowThreshold,omitempty"`
}

CoverageSection holds threshold check results for files or packages.

type DiffSection

type DiffSection struct {
	Threshold      *float64                    `json:"threshold,omitempty"`
	MeetsThreshold bool                        `json:"meetsThreshold"`
	Percentage     float64                     `json:"percentage"`
	Changes        []coverage.FileCoverageDiff `json:"changes,omitempty"`
}

DiffSection holds coverage difference data between current and base branches.

type Format

type Format string

Format specifies an output format.

const (
	FormatText     Format = "text"
	FormatMarkdown Format = "markdown"
	FormatJSON     Format = "json"
	FormatCSV      Format = "csv"
)

type Formatter

type Formatter interface {
	Format(report Report) string
}

Formatter produces a report string in a specific format.

func NewFormatter

func NewFormatter(format string) Formatter

NewFormatter creates a Formatter for the given format.

type GithubActionEmitter

type GithubActionEmitter struct{}

GithubActionEmitter writes GitHub Actions ::error annotations to the writer.

func (*GithubActionEmitter) Emit

func (e *GithubActionEmitter) Emit(w io.Writer, r Report)

type JSONFormatter

type JSONFormatter struct{}

JSONFormatter produces JSON output of the Report.

func (*JSONFormatter) Format

func (f *JSONFormatter) Format(r Report) string

type MarkdownFormatter

type MarkdownFormatter struct{}

MarkdownFormatter produces Markdown-formatted output for PR comments.

func (*MarkdownFormatter) Format

func (f *MarkdownFormatter) Format(r Report) string

type OutputConfig

type OutputConfig struct {
	Format              Format   `yaml:"format"`
	FileName            string   `yaml:"file-name"`
	ShowFileCoverage    ShowMode `yaml:"show-file-coverage"`
	ShowPackageCoverage ShowMode `yaml:"show-package-coverage"`
	ShowUncoveredLines  ShowMode `yaml:"show-uncovered-lines"`
	ShowDiff            ShowMode `yaml:"show-diff"`
	ShowAnnotations     ShowMode `yaml:"show-annotations"`
}

OutputConfig controls output format and section visibility.

func (*OutputConfig) ApplyDefaults

func (c *OutputConfig) ApplyDefaults()

ApplyDefaults sets zero-value fields to their defaults.

func (*OutputConfig) Validate

func (c *OutputConfig) Validate() error

Validate checks that all OutputConfig values are valid.

type Report

type Report struct {
	Pass          bool           `json:"pass"`
	TotalCoverage coverage.Stats `json:"totalCoverage"`

	FileCoverage    *CoverageSection `json:"fileCoverage,omitempty"`
	PackageCoverage *CoverageSection `json:"packageCoverage,omitempty"`
	UncoveredLines  []coverage.Stats `json:"uncoveredLines,omitempty"`
	Diff            *DiffSection     `json:"diff,omitempty"`
	Annotations     []coverage.Stats `json:"annotations,omitempty"`
}

Report is a view model containing only sections that should be displayed. nil pointer fields indicate a section is hidden.

func BuildReport

func BuildReport(input BuildInput, cfg OutputConfig) Report

BuildReport filters BuildInput through OutputConfig to produce a Report containing only sections that should be displayed.

type ShowMode

type ShowMode string

ShowMode controls when a report section is displayed.

const (
	ShowAlways    ShowMode = "always"
	ShowNever     ShowMode = "never"
	ShowThreshold ShowMode = "threshold" // default for file/package coverage
	ShowOnFail    ShowMode = "on-fail"   // default for uncovered lines
	ShowAuto      ShowMode = "auto"      // default for diff, annotations
)

type TextFormatter

type TextFormatter struct{}

TextFormatter produces plain-text output identical to the previous ReportForHuman.

func (*TextFormatter) Format

func (f *TextFormatter) Format(r Report) string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL