render

package
v0.25.1 Latest Latest
Warning

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

Go to latest
Published: Nov 17, 2026 License: MIT Imports: 22 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 composes what loupe shows and sends.

Index

Constants

View Source
const MetaPrefix = "<!-- loupe-meta "

MetaPrefix opens the hidden loupe-meta comment; publish's round count reads it to recognize a loupe review's body without needing that attempt's digest.

Variables

View Source
var (
	ErrNoRecord      = errors.New("it carries no findings record")
	ErrRecordOmitted = errors.New("its findings record was left out to fit GitHub's length limit")
)

Functions

func AnchorsAsNotes

func AnchorsAsNotes(body string) string

AnchorsAsNotes shows each anchor as the number of the round it opens, for a terminal: its checksum means nothing to a reader, and the payload view still shows the exact bytes.

func Body

func Body(in Input) string

func CodeSpan

func CodeSpan(s string) string

CodeSpan follows the CommonMark rule so no content can close the span early. Contents are not HTML-escaped because GitHub shows character references inside a span literally.

func CommentPillsAsWords

func CommentPillsAsWords(comment string) string

CommentPillsAsWords is PillsAsWords for an inline comment, whose row is its first line.

func Comments

func Comments(in Input) []github.ReviewComment

func EscapeHTML

func EscapeHTML(s string) string

func Fence

func Fence(s string) string

func ForDisplay

func ForDisplay(s string) string

ForDisplay makes controls and bidirectional formatting characters visible so a preview cannot hide or reorder text. It is for display only; payloads are sent verbatim.

func ForDisplayANSI

func ForDisplayANSI(s string) string

ForDisplayANSI is ForDisplay for styled terminal output: well-formed SGR sequences survive and every other escape sequence is left inert and visible.

func ForDisplayMarkdown

func ForDisplayMarkdown(md string) string

ForDisplayMarkdown is ForDisplay for Markdown handed to glamour, which decodes character references in text with html.UnescapeString after any escaping of the source, so a reference to a hidden character is escaped in its decoded form.

func IsLoupe

func IsLoupe(body string) bool

IsLoupe reports whether body carries a loupe-meta line outside a fence, which is how loupe knows its own reviews.

func MetaRound

func MetaRound(body string) int

func MetaSource

func MetaSource(body string) string

MetaSource is the src= value on the marker line StickyRounds reads, or on a plain review's last marker line, empty when there is none.

func OneLine

func OneLine(s string) string

OneLine keeps an interpolated field from breaking out of its tag or opening a fence.

func PillsAsWords

func PillsAsWords(body string) string

PillsAsWords shows each severity pill in a body's rows as its word, for a terminal that shows the body as raw Markdown, where a pill would otherwise be a line of HTML. Only the <summary> lines loupe generates are touched, so authored text, fenced or not, keeps its bytes.

func PreviousRound

func PreviousRound(earlier []string) (int, string)

PreviousRound reads the newest collapsed round's number and commit, preferring the full SHA its footer links to over the abbreviated one in its summary. It returns 0 when there is no earlier round or it cannot be read.

func PublicationID

func PublicationID(body string) string

MetaRound is the round= value on the marker line MetaSource reads, 0 when there is none. PublicationID is the publication id of body's current round, empty when it has none. A sticky body keeps each earlier round's reconciliation marker above its own, so the last one outside a fence is the current round's.

func ReadRecord

func ReadRecord(body string) ([]RecordFinding, []RecordAssessment, error)

ReadRecord reads back the findings and assessments a body's record holds. Any doubt is an error and never a partial list, because a wrong previous round makes a reviewer drop an unfixed finding.

func RecordAsNote

func RecordAsNote(body string) string

RecordAsNote shows the record as a line a person can read, for a terminal that shows the body as raw Markdown. The record copies findings the body already shows, so the note names how many rather than repeating them.

func StickyRounds

func StickyRounds(body string) (rounds int, sticky bool)

StickyRounds is the sticky= count on body's loupe-meta line, and whether the line carries the key at all. A key whose count is not a number still marks the review as sticky, so it is read back and refused rather than skipped.

Types

type Finding

type Finding struct {
	ID           string
	Title        string
	Body         string
	Location     *Location
	General      bool
	Label        string
	Blocking     bool
	Confidence   string
	Severity     string
	Verified     string
	Impact       string
	References   []string
	SuggestedFix string
}

type Input

type Input struct {
	Owner, Repo   string
	Number, Round int
	HeadSHA       string
	Inline        string
	Summary       string
	Digest        string
	PublicationID string
	// Source is name[@version], already validated; empty omits it from the footer and loupe-meta.
	Source string
	// Model is the reviewer's model id, already validated; empty omits it from the footer and loupe-meta.
	Model string
	// Unattended marks a review published without a human's confirmation, per constitution 2.0.0.
	Unattended bool
	// Findings are the published findings; render does no filtering.
	Findings []Finding
	// Excluded, Withdrawn, Reinstated and Regraded are draft.GateCountsOf, over the whole draft, published findings
	// included.
	Excluded, Withdrawn, Reinstated, Regraded int
	// Sticky marks a body that later rounds edit in place; nil is an ordinary review.
	Sticky *StickyInput
	// Assessments rides in the findings record only, so the next round can carry an open finding forward.
	Assessments []RecordAssessment
}

type Location

type Location struct {
	Path      string
	Side      string
	Line      int
	StartLine int
}

type RecordAssessment

type RecordAssessment struct {
	Ref     string        `json:"ref"`
	Status  string        `json:"status"`
	Finding RecordEarlier `json:"finding"`
}

RecordAssessment is draft.Assessment as the record holds it: the round's status for an earlier finding.

type RecordEarlier

type RecordEarlier struct {
	RecordFinding
	FiledIn RecordFiledIn `json:"filedIn"`
}

type RecordFiledIn

type RecordFiledIn struct {
	Round     int    `json:"round"`
	ReviewURL string `json:"reviewUrl"`
	Commit    string `json:"commit,omitempty"`
}

type RecordFinding

type RecordFinding struct {
	ID       string          `json:"id"`
	Title    string          `json:"title"`
	Body     string          `json:"body"`
	Location *RecordLocation `json:"location"`
	Label    string          `json:"label"`
	Blocking bool            `json:"blocking"`
}

RecordFinding is one published finding as the record holds it. Its JSON is publish.EnvelopeFinding's, so a round read back from GitHub and one read from a receipt have one shape.

type RecordLocation

type RecordLocation struct {
	Path      string `json:"path"`
	Side      string `json:"side"`
	Line      int    `json:"line"`
	StartLine int    `json:"startLine,omitempty"`
}

type Round

type Round struct {
	N      int
	Commit string
	Anchor string
	Block  string
	// Edited marks a round whose checksum did not match what GitHub returned. It is carried as found, and its anchor
	// is written again over what was found, so the edit is named by one publication only.
	Edited bool
}

Round is one collapsed round as the next body carries it: its anchor line, then its <details> block. The length limit drops a round whole, so a block never loses its anchor.

func ReadSticky

func ReadSticky(body string) (earlier []Round, rounds int, err error)

ReadSticky reads a sticky body back into the collapsed rounds the next body holds, newest first: the round the body shows, demoted, then the rounds it already held. rounds is its sticky= count. A body with anchors is read by them alone. One without is read by the legacy reader once, and what it returns is anchored, so the next body has anchors.

type StickyInput

type StickyInput struct {
	// Rounds is how many rounds have been published into the review, this one included, dropped ones too.
	Rounds int
	// Earlier holds the collapsed rounds as ReadSticky returns them, newest first.
	Earlier []Round
	// PrevRound and PrevSHA name the round before this one for the footer's compare link. They are kept apart from
	// Earlier, which the length limit may empty, and when unset they are Earlier's newest round's.
	PrevRound int
	PrevSHA   string
	// Note is shown under this round's footer while the round is the newest, and dropped when a later round collapses
	// it. Empty writes no note.
	Note string
}

StickyInput is what a sticky body carries beyond its own round.

Jump to

Keyboard shortcuts

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