review

package
v0.2.2 Latest Latest
Warning

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

Go to latest
Published: Oct 29, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const MaxCommits = 100

MaxCommits bounds the commits one observation captures: the newest of the branch's merge-base..HEAD range.

Variables

This section is empty.

Functions

func Error

func Error(status int, format string, values ...any) error

func FormatComments

func FormatComments(comments []ReviewComment, includeResolved bool) string

FormatComments exports comments using their computed placements. Unresolved exports include every open comment; stale and carried ones are tagged.

func Message

func Message(value string) *string

func PatchContext

func PatchContext(patch, side string, start, end int) (string, bool)

func PatchDigest added in v0.2.2

func PatchDigest(patch FilePatch) string

PatchDigest identifies a file's stored patch text so review marks carry between snapshots only while the reviewed change is identical.

func Permanent added in v0.2.1

func Permanent(err error) bool

Permanent reports whether retrying the same request cannot succeed: a client-class rejection other than timeout or rate limiting. Unclassified errors, timeouts, throttling and server failures are transient.

func RemoteRepositoryKey added in v0.2.1

func RemoteRepositoryKey(remote string) string

RemoteRepositoryKey is the initial repository identity enrolled for a sanitized remote URL. Collectors and the server's GitHub integration share it, so pull requests group with checkouts cloned from the same URL.

func RemoteRepositoryName

func RemoteRepositoryName(remote, fallback string) string

Types

type Applicability

type Applicability string

Applicability says where a stream comment applies in a viewed snapshot.

const (
	Anchored   Applicability = "anchored"
	Moved      Applicability = "moved"
	Outdated   Applicability = "outdated"
	Unchanged  Applicability = "unchanged"
	OtherScope Applicability = "other-scope"
	Unknown    Applicability = "unknown"
)

func (Applicability) Inline added in v0.2.1

func (applicability Applicability) Inline() bool

Inline reports whether the comment renders on lines of the viewed snapshot.

func (Applicability) Stale added in v0.2.1

func (applicability Applicability) Stale() bool

Stale reports whether the comment was written against code that changed.

type ChangedFile

type ChangedFile struct {
	ID             string  `json:"id"`
	Path           string  `json:"path"`
	OldPath        *string `json:"oldPath"`
	Status         string  `json:"status"`
	IndexStatus    string  `json:"indexStatus"`
	WorktreeStatus string  `json:"worktreeStatus"`
	Additions      int     `json:"additions"`
	Deletions      int     `json:"deletions"`
	Binary         bool    `json:"binary"`
	Fingerprint    string  `json:"fingerprint"`
	Recreated      bool    `json:"recreated,omitempty"`
}

func FileFor added in v0.2.1

func FileFor(path string, files []ChangedFile) (ChangedFile, bool)

FileFor finds a comment's file by path, or by a rename away from that path.

type CommentAnchor added in v0.2.1

type CommentAnchor struct {
	Before string `json:"before"`
	After  string `json:"after"`
}

func PatchAnchor added in v0.2.1

func PatchAnchor(patch, side string, start, end int) *CommentAnchor

PatchAnchor captures up to three contiguous same-side hunk lines before and after a selection, as content without diff prefixes.

type CommentCarriedFrom added in v0.2.1

type CommentCarriedFrom struct {
	VersionID string `json:"versionId"`
	Side      string `json:"side"`
	Start     int    `json:"start"`
	End       int    `json:"end"`
}

type CommentPlacement added in v0.2.1

type CommentPlacement struct {
	Applicability Applicability `json:"applicability"`
	Side          string        `json:"side"`
	Start         int           `json:"start"`
	End           int           `json:"end"`
}

func Locate added in v0.2.1

func Locate(comment ReviewComment, viewed *RepositoryDiff, patch PatchReader) (CommentPlacement, error)

Locate places a stream comment in the viewed snapshot of a scope. Line comments re-anchor by content: the preserved code block must occur exactly once on the comment's side, preferring a match whose captured surrounding lines also match. Ambiguity never anchors.

type Commit added in v0.2.2

type Commit struct {
	OID         string   `json:"oid"`
	Parents     []string `json:"parents"`
	PatchID     string   `json:"patchId,omitempty"`
	Subject     string   `json:"subject"`
	Body        string   `json:"body"`
	AuthorName  string   `json:"authorName"`
	AuthoredAt  int64    `json:"authoredAt"`
	CommittedAt int64    `json:"committedAt"`
}

Commit is captured commit metadata. Merge commits have several parents and no captured diff.

func (Commit) Merge added in v0.2.2

func (commit Commit) Merge() bool

type CommitRange added in v0.2.2

type CommitRange struct {
	Count   int `json:"count"`
	Omitted int `json:"omitted"`
}

CommitRange counts captured commits and those omitted beyond MaxCommits.

type CommitSummary added in v0.2.2

type CommitSummary struct {
	Commit
	Merge     bool `json:"merge"`
	FileCount int  `json:"fileCount"`
	Additions int  `json:"additions"`
	Deletions int  `json:"deletions"`
}

CommitSummary is a stored commit with its captured diff's totals.

type ComparisonKind added in v0.2.1

type ComparisonKind string

ComparisonKind describes captured endpoints independently of deployment or scope aliases.

const (
	ComparisonCombined    ComparisonKind = "combined"
	ComparisonUncommitted ComparisonKind = "uncommitted"
	ComparisonStaged      ComparisonKind = "staged"
	ComparisonUnstaged    ComparisonKind = "unstaged"
	ComparisonCommitted   ComparisonKind = "committed"
	ComparisonPatch       ComparisonKind = "patch"
)
const ComparisonCommit ComparisonKind = "commit"

ComparisonCommit compares one commit with its first parent.

type DiffMode

type DiffMode string
const (
	DiffAll         DiffMode = "all"
	DiffStaged      DiffMode = "staged"
	DiffUnstaged    DiffMode = "unstaged"
	DiffUncommitted DiffMode = "uncommitted"
	DiffCommitted   DiffMode = "committed"
)
const DiffCommit DiffMode = "commit"

DiffCommit names a captured commit's own diff. It is not a review scope: ParseDiffMode rejects it, so comments and reviewed marks never target it.

func ParseDiffMode

func ParseDiffMode(value string) (DiffMode, error)

type FileContents

type FileContents struct {
	Before string `json:"before"`
	After  string `json:"after"`
}

type FilePatch

type FilePatch struct {
	Patch    string        `json:"patch"`
	Message  *string       `json:"message"`
	Contents *FileContents `json:"contents,omitempty"`
}

type PatchReader added in v0.2.1

type PatchReader func(ChangedFile) (FilePatch, error)

PatchReader returns the viewed snapshot's stored patch for one of its files.

type RepositoryDiff

type RepositoryDiff struct {
	ID             string         `json:"id"`
	VersionID      string         `json:"versionId"`
	LocationID     *string        `json:"locationId"`
	RepositoryID   *string        `json:"repositoryId"`
	Source         string         `json:"source"`
	Root           string         `json:"root"`
	Name           string         `json:"name"`
	Branch         string         `json:"branch"`
	Head           *string        `json:"head"`
	Mode           DiffMode       `json:"mode"`
	ComparisonKind ComparisonKind `json:"comparisonKind,omitempty"`
	Files          []ChangedFile  `json:"files"`
	Revision       string         `json:"revision"`
}

type RequestError

type RequestError struct {
	Status int
	Detail string
}

func (*RequestError) Error

func (err *RequestError) Error() string

type ReviewComment

type ReviewComment struct {
	ID          string        `json:"id"`
	DiffID      string        `json:"diffId"`
	VersionID   string        `json:"versionId"`
	Path        string        `json:"path"`
	Scope       DiffMode      `json:"scope"`
	Fingerprint string        `json:"fingerprint"`
	Target      string        `json:"target,omitempty"`
	Side        string        `json:"side"`
	Start       int           `json:"start"`
	End         int           `json:"end"`
	Code        string        `json:"code"`
	Body        string        `json:"body"`
	Status      string        `json:"status"`
	CreatedAt   float64       `json:"createdAt"`
	Origin      *ReviewOrigin `json:"origin,omitempty"`
	// Anchor holds same-side content lines around the selection, captured at creation.
	Anchor *CommentAnchor `json:"anchor,omitempty"`
	// CarriedFrom records the original selection of a comment kept open at file level.
	CarriedFrom *CommentCarriedFrom `json:"carriedFrom,omitempty"`
	// Placement is computed for the viewed snapshot and never persisted.
	Placement *CommentPlacement `json:"placement,omitempty"`
}

func (ReviewComment) Valid

func (comment ReviewComment) Valid() bool

type ReviewFileOrigin

type ReviewFileOrigin struct {
	Status  string  `json:"status"`
	OldPath *string `json:"oldPath"`
}

type ReviewMark

type ReviewMark struct {
	DiffID      string   `json:"diffId"`
	VersionID   string   `json:"versionId"`
	FileID      string   `json:"fileId"`
	FileVersion string   `json:"fileVersion"`
	Scope       DiffMode `json:"scope"`
}

type ReviewOrigin

type ReviewOrigin struct {
	DiffID     string           `json:"diffId"`
	VersionID  string           `json:"versionId"`
	Source     string           `json:"source"`
	Repository string           `json:"repository"`
	Branch     string           `json:"branch"`
	Head       *string          `json:"head"`
	Revision   string           `json:"revision"`
	File       ReviewFileOrigin `json:"file"`
}

type ScopeSummary added in v0.2.1

type ScopeSummary struct {
	Scope          DiffMode       `json:"scope"`
	ComparisonKind ComparisonKind `json:"comparisonKind"`
	FileCount      int            `json:"fileCount"`
}

type Source

type Source interface {
	Root() string
	Kind() string
	Support() Support
	Snapshot(context.Context, DiffMode) (RepositoryDiff, error)
	Patch(context.Context, DiffMode, ChangedFile, *string) (FilePatch, error)
	Contents(context.Context, DiffMode, ChangedFile, *string) (FileContents, error)
}

type Support

type Support struct {
	Scopes          []DiffMode
	Refresh         bool
	StagingMetadata bool
	FileContents    bool
}

Jump to

Keyboard shortcuts

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