archiveprune

package
v0.69.5 Latest Latest
Warning

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

Go to latest
Published: Sep 1, 2026 License: MIT Imports: 18 Imported by: 0

Documentation

Overview

Package archiveprune audits and, only under explicit apply, deletes local clones of repositories confirmed archived on GitHub.

Deleting a clone is destructive. What makes it acceptable here is narrow: an archived repository still exists on GitHub, so a deleted clone is re-clonable. That argument collapses the moment the clone holds something GitHub does not — an uncommitted edit, a stash, a commit or branch or tag that was never pushed, or a linked worktree or WB Work Log claim that still needs the clone to exist. Every check in Evaluate exists to protect that one argument; a check that cannot be completed (GitHub unreachable, a ref that cannot be resolved) makes the clone not deletable, never "probably fine" — failing closed is the only correct default for an operation this destructive.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Options

type Options struct {
	ProjectsRoot string
	// Filter restricts to repositories whose "org/name" slug contains this
	// substring, matching the fleet-wide --filter convention used elsewhere.
	Filter string
	// Apply performs deletions. Without it, Clean only plans: it runs the
	// exact same evaluation and reports the exact same eligibility, but never
	// calls os.RemoveAll.
	Apply bool
	// DeleteUntracked authorizes the deliberately narrow exception to the usual
	// clean-working-tree predicate. It has no effect without Apply. Clean still
	// plans and itemizes untracked paths by default; this flag is the separate,
	// explicit authority required before it can delete them.
	DeleteUntracked bool
	// Progress, when set, receives one "[n/N] org/repo" line per repository as
	// it is evaluated, so a long fleet sweep is distinguishable from a hang.
	Progress io.Writer
	// contains filtered or unexported fields
}

Options selects and drives one clean run.

type Outcome

type Outcome struct {
	Apply           bool     `json:"apply" yaml:"apply"`
	DeleteUntracked bool     `json:"delete_untracked" yaml:"delete_untracked"`
	Results         []Result `json:"results" yaml:"results"`
}

Outcome is a whole clean run.

func Clean

func Clean(ctx context.Context, options Options) (Outcome, error)

Clean discovers local clones below options.ProjectsRoot, evaluates every one whose slug matches options.Filter, and — only under options.Apply — deletes the ones that pass every safety check. It never removes a clone it has not itself confirmed archived and clean in this exact run.

type Result

type Result struct {
	Repository string `json:"repository" yaml:"repository"`
	Path       string `json:"path" yaml:"path"`
	// Eligible reports whether the clone satisfies every safety check,
	// independent of whether Apply was requested.
	Eligible bool `json:"eligible" yaml:"eligible"`
	// Applied is true only when Apply was requested, the clone was eligible,
	// and the deletion itself succeeded.
	Applied bool `json:"applied" yaml:"applied"`
	// Reason names, for an eligible clone, why it is safe; for an ineligible
	// one, every failing check, joined so the report is self-explanatory
	// without cross-referencing anything else.
	Reason string `json:"reason" yaml:"reason"`
	// Untracked itemizes every untracked file and directory found during the
	// plan. It is present for dry runs and refusals, never inferred from a count.
	Untracked []UntrackedEntry `json:"untracked,omitempty" yaml:"untracked,omitempty"`
	// ReceiptPath names the durable, itemized WB receipt written before an
	// explicitly authorised untracked deletion and finalized before pruning.
	ReceiptPath string `json:"receipt_path,omitempty" yaml:"receipt_path,omitempty"`
	// Error is set only when the deletion itself failed after the clone was
	// judged eligible.
	Error string `json:"error,omitempty" yaml:"error,omitempty"`
	// contains filtered or unexported fields
}

Result is the plan or outcome for one local clone.

func Evaluate

func Evaluate(ctx context.Context, projectsRoot string, repo discover.Repo) Result

Evaluate judges a single clone against the full safety predicate. It never mutates anything; Clean is the only mutator, and only under Apply.

type UntrackedEntry added in v0.67.5

type UntrackedEntry struct {
	Path string `json:"path" yaml:"path"`
	Kind string `json:"kind" yaml:"kind"`
	Size int64  `json:"size" yaml:"size"`
	// contains filtered or unexported fields
}

UntrackedEntry is one exact untracked filesystem entry observed in a clone. Path is always relative to the clone root; Size is bytes for a regular file and the filesystem-reported size for a directory.

Jump to

Keyboard shortcuts

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