Documentation
¶
Index ¶
- func GenerateAnnotations(result *AnalysisResult) []*github.Annotation
- func GetAddedLinesByFile(fileDiffs []*FileDiff) map[string][]int
- func NormalizeFilename(filename string) string
- func SerializeProfiles(profiles []*Profile) ([]byte, error)
- func ValidateProfile(p *Profile) error
- type AnalysisResult
- type CoverageComparison
- type CoverageStats
- type FileCoverage
- type FileDiff
- type Profile
- type ProfileBlock
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GenerateAnnotations ¶
func GenerateAnnotations(result *AnalysisResult) []*github.Annotation
GenerateAnnotations converts analysis result to GitHub Check Run annotations. Uses github.GroupIntoRanges to merge consecutive lines into ranges. Returns annotations with "notice" level as per GitHub Check Run API format.
func GetAddedLinesByFile ¶
GetAddedLinesByFile returns a map of filename to added line numbers. The filename is normalized to use the new name (after any renames). Binary files, deleted files, and non-Go files are excluded.
func NormalizeFilename ¶
NormalizeFilename removes the a/ or b/ prefix from diff filenames.
func SerializeProfiles ¶
SerializeProfiles converts profiles back to standard Go coverage format. This is used when saving merged coverage data.
func ValidateProfile ¶
ValidateProfile checks if a coverage profile is well-formed. It returns an error if the profile has invalid block data.
Types ¶
type AnalysisResult ¶
type AnalysisResult struct {
// UncoveredByFile maps filenames to their uncovered line numbers
UncoveredByFile map[string][]int
// TotalLines is the total number of instrumented lines across all profiles
TotalLines int
// TotalCovered is the total number of covered lines across all profiles
TotalCovered int
// DiffAddedLines is the total number of lines added in the diff
DiffAddedLines int
// DiffAddedCovered is the total number of covered lines among added lines
DiffAddedCovered int
}
AnalysisResult contains the results of coverage analysis.
func AnalyzeCoverage ¶
func AnalyzeCoverage(profiles []*Profile, addedLinesByFile map[string][]int) *AnalysisResult
AnalyzeCoverage cross-references coverage profiles with diff to find uncovered added lines. Coverage profiles are the primary source - we extract uncovered lines from them, then filter by the diff to only report lines that were added. It takes coverage profiles and a map of added lines by file (from GetAddedLinesByFile). Returns an AnalysisResult with uncovered lines grouped by file.
func (*AnalysisResult) GetSortedFiles ¶
func (r *AnalysisResult) GetSortedFiles() []string
GetSortedFiles returns a sorted list of files with uncovered lines. Useful for consistent output ordering.
func (*AnalysisResult) HasUncoveredLines ¶
func (r *AnalysisResult) HasUncoveredLines() bool
HasUncoveredLines returns true if there are any uncovered lines in the result.
type CoverageComparison ¶
type CoverageComparison struct {
BaseCoverage float64
HeadCoverage float64
Delta float64 // positive = improvement, negative = regression
Decreased bool
}
CoverageComparison holds the result of comparing two coverage reports.
func CompareCoverage ¶
func CompareCoverage(base, head *CoverageStats) *CoverageComparison
CompareCoverage compares base and head coverage stats. Returns a comparison showing the delta between base and head. If base is nil, it's treated as 0% coverage (first coverage report).
type CoverageStats ¶
type CoverageStats struct {
TotalStatements int
CoveredStatements int
Percentage float64
ByFile map[string]*FileCoverage
}
CoverageStats holds coverage statistics.
func CalculateCoverageStats ¶
func CalculateCoverageStats(profiles []*Profile) *CoverageStats
CalculateCoverageStats calculates coverage statistics from profiles. It computes overall coverage percentage and per-file breakdown. Coverage is calculated as: (covered statements / total statements) * 100
type FileCoverage ¶
type FileCoverage struct {
FileName string
TotalStatements int
CoveredStatements int
Percentage float64
}
FileCoverage holds coverage statistics for a single file.
type FileDiff ¶
type FileDiff struct {
// OldName is the original filename (a/path/to/file)
OldName string
// NewName is the new filename (b/path/to/file)
NewName string
// AddedLines contains the line numbers that were added in this diff
AddedLines []int
// IsBinary indicates if this is a binary file
IsBinary bool
// IsRenamed indicates if the file was renamed
IsRenamed bool
// IsDeleted indicates if the file was deleted
IsDeleted bool
}
FileDiff represents the changes to a single file in a diff.
type Profile ¶
type Profile struct {
FileName string
Mode string
Blocks []ProfileBlock
}
Profile represents a single coverage profile for a file.
func MergeProfiles ¶
MergeProfiles merges multiple coverage profiles into a single profile. It implements the gocovmerge algorithm, which merges coverage blocks at the block level, handling overlapping coverage from multiple test runs.
The algorithm: 1. Groups profiles by file name 2. For each file, merges all blocks using additive merging 3. Uses the mode from the first profile (all profiles must use same mode) 4. Returns merged profiles sorted by file name
func ParseProfiles ¶
ParseProfiles parses coverage data in standard Go coverage format. It returns a slice of Profile structs representing the coverage data.
func ParseProfilesFromFile ¶
ParseProfilesFromFile parses coverage data from a file path. This is primarily used when reading coverage files directly.
func ParseProfilesFromZip ¶
ParseProfilesFromZip extracts and parses all coverage files from a zip archive. It looks for files matching common coverage patterns (*.out, *.cov, coverage.txt). Returns all parsed profiles from all coverage files found in the archive.