Documentation
¶
Overview ¶
Package review contains helpers used by the `tusk review` command: file-filter lists mirroring the backend, pre-flight git checks, patch generation, and status polling.
Index ¶
- Constants
- Variables
- func BuildPathspecExclusions(extraExcludes []string, includes []string) []string
- func CheckOriginHead(repoRoot string) error
- func GitDir(repoRoot string) (string, error)
- func IsBaseResolutionError(err error) bool
- func IsPreflightError(err error) bool
- func Poll(ctx context.Context, client *api.TuskClient, auth api.AuthOptions, ...) (*backend.GetCodeReviewRunStatusResponseSuccess, error)
- func Preflight(repoRoot string) error
- func ReadTuskignore(repoRoot string) ([]string, error)
- func RepoRoot() (string, error)
- type BaseResolutionError
- type FileSummary
- type PatchOptions
- type PatchResult
- type PatchTooLargeError
- type PollOptions
- type PreflightError
- type SubmoduleError
Constants ¶
const ( SoftLineCap = 2_000 SoftFileCap = 50 HardLineCap = 10_000 HardFileCap = 200 HardBytesCap = 1 << 20 // 1 MiB )
Hard and soft caps. Hard caps abort with an error listing top contributors. Soft caps emit a stderr warning and continue.
Variables ¶
var DirectoriesToSkip = []string{
".git", ".vscode", ".idea",
"node_modules", "dist", "build", "out", ".next", ".nuxt", ".turbo",
".parcel-cache", ".svelte-kit", ".vercel", ".angular", ".nx", "bower_components",
"__pycache__", ".venv", "venv", "env", ".pytest_cache", ".mypy_cache", ".tox",
"target", ".gradle",
".bundle",
"vendor",
".terraform", ".serverless",
"assets", "coverage", "tmp", "temp", "logs", "generated", ".cache", ".sass-cache",
}
var ErrEmptyPatch = errors.New("empty patch")
ErrEmptyPatch is returned when the working tree diff against the base is empty (or empty after filtering).
var ExtensionsToSkip = []string{
".png", ".jpg", ".jpeg", ".gif", ".bmp", ".tif", ".tiff", ".ico", ".svg", ".webp", ".heic",
".mp3", ".wav", ".wma", ".ogg", ".flac", ".m4a", ".aac", ".midi", ".mid",
".mp4", ".avi", ".mkv", ".mov", ".wmv", ".m4v", ".3gp", ".3g2", ".rm", ".swf", ".flv", ".webm", ".mpg", ".mpeg",
".otf", ".ttf",
".pdf", ".doc", ".docx", ".xls", ".xlsx", ".ppt", ".pptx", ".rtf", ".odt", ".ods", ".odp",
".iso", ".bin", ".tar", ".zip", ".7z", ".gz", ".rar", ".bz2", ".xz",
".min.js", ".min.js.map", ".js.map", ".min.css", ".min.css.map",
".tfstate", ".tfstate.backup", ".parquet", ".pyc", ".pub", ".pem", ".lock", ".sqlite", ".db", ".env", ".log",
".class", ".dll", ".exe",
".psd", ".ai", ".sketch",
".stl", ".obj", ".dwg",
".bak", ".old", ".tmp",
}
var FilesToSkip = []string{
"pnpm-lock.yaml",
"package-lock.json",
".DS_Store",
".gitignore",
"bun.lockb",
"npm-debug.log",
"yarn-error.log",
"Thumbs.db",
"Gemfile.lock",
}
Functions ¶
func BuildPathspecExclusions ¶
BuildPathspecExclusions returns a list of git pathspec strings (each prefixed with `:(exclude,glob)`) that can be passed to `git diff` to filter out files the backend code-review pipeline would skip anyway, plus any user-supplied extras.
includes cancels individual default exclusions: any default pattern that doublestar-matches an include glob is dropped. This gives the user an escape hatch without needing git pathspec's more awkward include form.
func CheckOriginHead ¶
CheckOriginHead confirms that `origin/HEAD` is set on this clone, which `git merge-base` relies on for auto-detecting the clone pivot when the branch has no upstream. Returns a *PreflightError with remediation text when missing.
func GitDir ¶
GitDir returns the path to the .git directory (or worktree gitdir file) for the repository at repoRoot.
func IsBaseResolutionError ¶
IsBaseResolutionError reports whether err (or anything it wraps) is a *BaseResolutionError.
func IsPreflightError ¶
IsPreflightError reports whether err (or anything it wraps) is a *PreflightError.
func Poll ¶
func Poll(ctx context.Context, client *api.TuskClient, auth api.AuthOptions, runId string, opts PollOptions) (*backend.GetCodeReviewRunStatusResponseSuccess, error)
Poll blocks, polling the backend for the given runId, rendering progress to stderr as it goes, until the run reaches a terminal status (SUCCESS, FAILED, CANCELLED).
TTY mode: animated spinner redraws every ~100ms using the most recent display_message; backend is hit every Interval. Non-TTY: one line per message change (avoids spamming CI logs). Quiet: nothing to stderr; polling still happens so the backend heartbeat is kept fresh.
func Preflight ¶
Preflight runs the quick local checks that must pass before we try to generate a patch. It returns a *PreflightError for user-actionable failures and a plain error for unexpected ones (e.g. git not on PATH).
Emits a stderr warning (not an error) for detached HEAD. Detached HEAD doesn't prevent patch generation; the user is just told their results may look off.
func ReadTuskignore ¶
ReadTuskignore parses `.tuskignore` at the given repo root if present. Returns a list of glob patterns; comments and blanks are ignored. Missing file returns (nil, nil).
Types ¶
type BaseResolutionError ¶
type BaseResolutionError struct {
Message string
}
BaseResolutionError wraps merge-base or ref-resolution failures with the structured remediation UX from the plan.
func (*BaseResolutionError) Error ¶
func (e *BaseResolutionError) Error() string
type FileSummary ¶
FileSummary describes a single file's contribution to the patch, used to build "top contributors" lists for size-cap error messages.
type PatchOptions ¶
type PatchOptions struct {
RepoRoot string
ExtraExcludes []string
Includes []string
RegisterCleanup func(fn func()) // typically cmd.RegisterCleanup; may be nil for tests
// Stderr is where soft-warnings are written. Defaults to os.Stderr when nil.
Stderr *os.File
}
PatchOptions drives BuildPatch.
type PatchResult ¶
type PatchResult struct {
Patch []byte
LastPushedSha string
BaseRef string // The ref label the pivot resolved from ("@{u}" or "origin/HEAD").
BranchName string // Current branch (empty string on detached HEAD).
LocalHeadSha string // git rev-parse HEAD — informational, sent to backend for audit.
ChangedFiles []FileSummary
ChangedLines int
FileCount int
}
PatchResult is what BuildPatch returns on success.
Terminology (see v2-plan.md "Three roles of SHAs / refs"):
- LastPushedSha is the commit the sandbox will clone. It's guaranteed reachable on origin because the CLI resolves it from a remote-tracking ref (@{u}) or, for branches with no upstream, from merge-base with origin/HEAD. The uploaded patch is the diff between this SHA and the working tree.
- Review scope is NOT set from this SHA. The backend picks the review base branch (open PR's base, or repo default) server-side and diffs the reconstructed working tree against that.
func BuildPatch ¶
func BuildPatch(ctx context.Context, opts PatchOptions) (*PatchResult, error)
BuildPatch generates a binary-clean git patch of the current working tree against a resolved base SHA. Untracked files are added with `git add -N` (and the intent-to-add is undone both via a normal return path and via a signal-safe cleanup registered through opts.RegisterCleanup).
Filtering is always applied (EXTENSIONS/FILES/DIRECTORIES skip lists + .tuskignore + --exclude/--include). Returns ErrEmptyPatch if nothing survives filtering.
type PatchTooLargeError ¶
type PatchTooLargeError struct {
Reason string // "lines", "files", or "bytes"
Bytes int
Lines int
Files int
TopFiles []FileSummary
LimitMessage string // human-readable summary, e.g. "1.4MB (limit: 1MB)"
}
PatchTooLargeError is returned when the patch exceeds a hard cap.
func (*PatchTooLargeError) Error ¶
func (e *PatchTooLargeError) Error() string
type PollOptions ¶
type PollOptions struct {
// Interval between backend status polls. Default: 5s.
//
// Must stay well under the backend's heartbeat-abandonment window
// (currently 5 minutes) so live runs don't get reaped.
Interval time.Duration
// SpinnerInterval controls how often the TTY spinner redraws. Ignored
// when stderr is not a TTY or when Quiet is set. Default: 100ms.
SpinnerInterval time.Duration
// Quiet suppresses all stderr progress output entirely.
Quiet bool
// Stderr is where progress lines are written. Defaults to os.Stderr.
// Primarily for testing.
Stderr *os.File
}
PollOptions tunes the status-polling loop.
Spinner animation and backend polling are intentionally decoupled: the spinner ticks on its own ~100ms schedule for smooth visual feedback, while the backend is hit only every Interval seconds. A stale spinner frame remains smooth to the eye; a stale backend poll costs money.
type PreflightError ¶
type PreflightError struct {
Message string
}
PreflightError is returned for user-actionable pre-flight failures (e.g. mid-rebase, no origin/HEAD, shallow). The CLI renders the Message verbatim and exits with code 2.
func (*PreflightError) Error ¶
func (e *PreflightError) Error() string
type SubmoduleError ¶
type SubmoduleError struct {
Paths []string
}
SubmoduleError is returned when the generated patch contains submodule updates — these are not supported in v1.
func (*SubmoduleError) Error ¶
func (e *SubmoduleError) Error() string