render

package
v0.13.0 Latest Latest
Warning

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

Go to latest
Published: Nov 23, 2026 License: Apache-2.0 Imports: 29 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package render selects output formats and writes the JSON envelope.

Index

Constants

View Source
const (
	RuleBreaking    = "breaking"
	RuleDeprecation = "deprecation"
	RuleEOL         = "eol"
	RuleDrift       = "drift"
	RuleOutdated    = "outdated"
	RuleFailed      = "failed"
	RuleUnchecked   = "unchecked"
)

SARIF rule IDs. A vulnerability's rule ID is its OSV ID.

View Source
const ApproxMark = "≈"

ApproxMark prefixes a pin value that allows more than one version.

View Source
const AuditUncheckedTitle = "Not checked for vulnerabilities"

AuditUncheckedTitle heads audit's list of tool versions OSV wasn't asked about.

View Source
const DefaultMDMaxChars = 60_000

DefaultMDMaxChars is the default --md-max-chars, under GitHub's 65,536-character cap on comments.

View Source
const FixTitle = "Fix targets"

FixTitle heads the list of fix targets.

View Source
const InfoURI = "https://github.com/sassdavid/relgap"

InfoURI is the tool's home page in SARIF logs.

View Source
const SchemaVersion = "1"

SchemaVersion is the envelope version in schemas/report-v1.json.

View Source
const SuppressedTitle = "Suppressed"

SuppressedTitle heads the list of advisories a vulns.ignore entry or VEX statement suppresses.

View Source
const ToolName = "relgap"

ToolName is the value of the envelope's "tool" field.

View Source
const UncheckedTitle = "Not checked for vulnerabilities (VULNS ?)"

UncheckedTitle heads the list of pins OSV wasn't asked about.

Variables

This section is empty.

Functions

func AuditMarkdown added in v0.13.0

func AuditMarkdown(w io.Writer, a *report.Audit, failed []Error) error

AuditMarkdown writes the findings as a Markdown table with the same sections as AuditText. Mentions and issue references in advisory summaries are silenced. failed are the envelope errors of a saved report, listed under "Failed"; a report fresh from a run passes nil, since its pins carry their failures.

func AuditOpenVEX added in v0.13.0

func AuditOpenVEX(w io.Writer, a *report.Audit, now time.Time, version string) error

AuditOpenVEX writes the findings as an OpenVEX v0.2.0 document issued at now, one statement per advisory and tool version: affected with the fix target as the action statement, and the suppressed ones with the status that suppresses them, not_affected for a vulns.ignore entry. Products are the purls of the advisories' packages at the tool versions.

func AuditRules added in v0.13.0

func AuditRules() []string

AuditRules returns the IDs of the fixed rules in audit's SARIF, in their order there.

func AuditSARIF added in v0.13.0

func AuditSARIF(a *report.Audit, problems []scan.Problem, version string) *sarif.Log

AuditSARIF returns a SARIF log with a result per finding and pin location, the suppressed ones marked with a suppression, per tool version OSV wasn't asked about and pin location, per pin whose version lookup failed and per file that didn't parse. Results don't depend on --fail-on. Rules are failed and unchecked, then one rule per OSV ID.

func AuditText added in v0.13.0

func AuditText(w io.Writer, a *report.Audit, color bool) error

AuditText writes the findings as an aligned table, then the advisories, the fix targets, the suppressed findings, the unchecked tool versions and a summary. With color it marks high and critical ratings red (the tty format).

func DigestMarkdown

func DigestMarkdown(w io.Writer, d *report.Digest, failed []Error, notes []string) error

DigestMarkdown writes d as PR-ready Markdown: counts, then breaking changes and security entries of every version, then one <details> block per version with the other kinds. A "Not digested" section, which lists failed digests and pins without a digest, comes first so truncation never cuts it, then a --summarize summary labelled as LLM output.

func DigestText

func DigestText(w io.Writer, d *report.Digest, color bool) error

DigestText writes d as plain text, breaking changes first and entries grouped by version. A --summarize summary comes first, labelled as LLM output. With color it adds ANSI bold headings and red breaking changes (the tty format).

func DriftMarkdown

func DriftMarkdown(w io.Writer, d *report.Drift, o DriftOptions) error

DriftMarkdown writes the matrix as a Markdown table, the tools left out as a list and a summary.

func DriftRules added in v0.7.0

func DriftRules() []string

DriftRules returns the IDs of the rules in drift's SARIF, in their order there.

func DriftSARIF

func DriftSARIF(d *report.Drift, problems []scan.Problem, version string) *sarif.Log

DriftSARIF returns a SARIF log with a result per drifted pin (a compared pin whose version differs from its tool's reference version), per file that didn't parse and per tool whose latest version couldn't be listed.

func DriftText

func DriftText(w io.Writer, d *report.Drift, o DriftOptions) error

DriftText writes the matrix (a row per repo, a column per drifting tool), the tools left out and a summary.

func JSON

func JSON(w io.Writer, v any) error

JSON writes v as indented JSON followed by a newline.

func LatestAffected added in v0.13.0

func LatestAffected(f *enrich.Fix) string

LatestAffected is the warning for a fix target whose latest release still has advisories, such as "latest 1.35.0 still has GO-2025-3521".

func OutdatedMarkdown

func OutdatedMarkdown(w io.Writer, o *report.Outdated) error

OutdatedMarkdown writes the pins as a Markdown table followed by notes.

func OutdatedRules added in v0.7.0

func OutdatedRules() []string

OutdatedRules returns the IDs of the fixed rules in outdated's SARIF, in their order there.

func OutdatedSARIF

func OutdatedSARIF(o *report.Outdated, problems []scan.Problem, version string) *sarif.Log

OutdatedSARIF returns a SARIF log with a result per pin behind latest, per pin on an EOL cycle, per pin whose upgrade has breaking changes or deprecations, per advisory that affects a pin, per pin or file that failed, and per pin OSV wasn't asked about. Results don't depend on --fail-on. Rules are in --fail-on order, then failed and unchecked, then one rule per OSV ID.

func OutdatedText

func OutdatedText(w io.Writer, o *report.Outdated, color bool) error

OutdatedText writes the pins as an aligned table followed by notes. With color it marks outdated versions yellow, current ones green and breaking counts red (the tty format). Skipped pins are left out; JSON lists them.

func PinLocation

func PinLocation(l scan.Location) string

PinLocation formats a location as repo/file:line, leaving out a "." repo and a zero line.

func PinsMarkdown

func PinsMarkdown(w io.Writer, pins []scan.Pin, unresolved bool) error

PinsMarkdown writes pins as a Markdown table.

func PinsText

func PinsText(w io.Writer, pins []scan.Pin, unresolved bool) error

PinsText writes pins as an aligned table. unresolved swaps the TOOL column for RAW NAME.

func SARIFRule added in v0.7.0

func SARIFRule(id string) sarif.Rule

SARIFRule returns the rule with id, one of the Rule constants, or a zero rule.

func SourceTestText

func SourceTestText(w io.Writer, t *report.SourceTest) error

SourceTestText writes what each source of a registry entry produced as an aligned table, followed by the documents, warnings and errors of each source.

func TruncateMarkdown added in v0.2.0

func TruncateMarkdown(md string, limit int, hint string) string

TruncateMarkdown returns md cut to at most limit characters (Unicode code points). It cuts between table rows, list items and sections, and ends with a footer that counts what was cut and names the first cut section. A limit of 0 or less, or md within the limit, returns md.

func UseColor

func UseColor(mode ColorMode, lookup func(string) (string, bool), isTTY bool) bool

UseColor reports whether to emit ANSI colors. --color always or never wins, then NO_COLOR, then CLICOLOR_FORCE, then terminal detection.

Types

type ColorMode

type ColorMode string

ColorMode is the --color flag value.

const (
	ColorAuto   ColorMode = "auto"
	ColorAlways ColorMode = "always"
	ColorNever  ColorMode = "never"
)

Color modes.

func ParseColorMode

func ParseColorMode(s string) (ColorMode, error)

ParseColorMode validates a --color value.

type DriftOptions

type DriftOptions struct {
	All   bool // a column for every tool, drifting or not
	Color bool // yellow outliers (the tty format)
}

DriftOptions says how to lay out the drift matrix.

type Envelope

type Envelope struct {
	SchemaVersion string    `json:"schema_version"`
	Tool          string    `json:"tool"`
	Version       string    `json:"version"`
	GeneratedAt   time.Time `json:"generated_at"`
	Data          any       `json:"data"`
	Errors        []Error   `json:"errors"`
	Page          *Page     `json:"page,omitempty"` // set by the MCP server when it splits a result
}

Envelope wraps every JSON output.

func NewEnvelope

func NewEnvelope(version string, now time.Time, data any) Envelope

NewEnvelope returns an envelope with no errors, stamped with now in UTC to the second.

type Error

type Error struct {
	Target  string `json:"target,omitempty"`
	Message string `json:"message"`
}

Error is a per-target error carried in the envelope.

type Format

type Format string

Format is an output format selected with --format.

const (
	FormatAuto    Format = ""
	FormatTTY     Format = "tty"
	FormatPlain   Format = "plain"
	FormatMD      Format = "md"
	FormatJSON    Format = "json"
	FormatCSV     Format = "csv"
	FormatSARIF   Format = "sarif"
	FormatGitHub  Format = "github"  // GitHub Actions workflow commands, which show as annotations
	FormatOpenVEX Format = "openvex" // an OpenVEX v0.2.0 document
)

Output formats. FormatAuto resolves to tty or plain depending on stdout.

func AllFormats

func AllFormats() []Format

AllFormats lists the formats --format accepts.

func OutFormats added in v0.2.0

func OutFormats() []Format

OutFormats lists the formats --out accepts. tty is left out because a file is never a terminal.

func ParseFormat

func ParseFormat(s string) (Format, error)

ParseFormat validates a --format value. The empty string means auto.

func (Format) Check

func (f Format) Check(allowed ...Format) error

Check returns an error unless f is one of allowed.

func (Format) Resolve

func (f Format) Resolve(stdoutIsTTY bool) Format

Resolve turns FormatAuto into tty (stdout is a terminal) or plain.

type Output added in v0.2.0

type Output struct {
	Format Format
	Path   string
}

Output is one --out value: a format and the file it goes to.

func ParseOutputs added in v0.2.0

func ParseOutputs(specs []string) ([]Output, error)

ParseOutputs validates --out values of the form format=path.

type Page

type Page struct {
	Items      string `json:"items"`                 // what was split, such as "entries"
	Returned   int    `json:"returned"`              // items in this page
	Total      int    `json:"total"`                 // items in the whole result
	NextCursor string `json:"next_cursor,omitempty"` // empty on the last page
}

Page says which part of a split result an envelope holds.

type Sink added in v0.2.0

type Sink struct {
	Stdout     io.Writer
	Format     Format
	Outputs    []Output
	MDMaxChars int    // 0 means no limit
	Command    string // named in the truncation footer, such as "relgap drift"
}

Sink sends one report to stdout in the --format format and to every --out file.

func (Sink) Write added in v0.2.0

func (s Sink) Write(write WriteFunc) error

Write renders the report once per target. Markdown is cut to MDMaxChars.

type WriteFunc added in v0.2.0

type WriteFunc func(w io.Writer, f Format) error

WriteFunc writes one report in format f.

Jump to

Keyboard shortcuts

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