render

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Nov 17, 2026 License: Apache-2.0 Imports: 24 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"
)

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 DefaultMDMaxChars = 60_000

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

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 ToolName = "relgap"

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

Variables

This section is empty.

Functions

func DigestMarkdown

func DigestMarkdown(w io.Writer, d *report.Digest) 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 --summarize summary comes first, 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 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 OutdatedMarkdown

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

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

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, and per pin or file that failed. Results don't depend on --fail-on. Rules are in --fail-on order, then failed, 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 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
)

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