whatchanged

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Jul 11, 2026 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Overview

Package whatchanged produces the "what changed" delta between two GitOps revisions: a path-scoped unified diff (the actual landed change). It is the differentiating core of RunLore's investigation spine.

Index

Constants

View Source
const MaxWindowRevisions = 10

MaxWindowRevisions caps how many in-window revisions a single GitOps object (Flux Kustomization / Argo CD Application) emits (G3). It bounds the "what changed" output so a wide window on a busy monorepo can't flood the model with hundreds of Changes. Shared by the flux and argocd providers, which pass it to RevisionsInWindow.

Variables

This section is empty.

Functions

func WithCloneCache

func WithCloneCache(ctx context.Context) (context.Context, func())

WithCloneCache returns a derived context carrying a clone cache, plus a cleanup func that removes every clone the cache created. Wrap a batch of diffs that may hit the same repo (the what_changed tool's change loop) so each source repo is cloned at most once; call the returned func when the batch is done.

Types

type Differ

type Differ struct {
	// TokenSource mints a GitHub App installation token for HTTPS clone auth in
	// Remote/RemoteFromParent. It is called once per clone so a short-lived
	// (~1h) installation token stays fresh across a long-running agent. nil
	// disables auth (e.g. public or local repos).
	TokenSource func(context.Context) (string, error)
}

Differ computes path-scoped diffs between Git revisions.

func (*Differ) CommitTime added in v0.9.0

func (d *Differ) CommitTime(ctx context.Context, url, rev string) (time.Time, error)

CommitTime clones url (via the batch clone cache when present) and returns the committer timestamp of rev. This is the time the change actually landed in Git — the anchor for aligning a GitOps Change against kube_events / pod-log timestamps (RunLore B1: Change.When was never populated for Flux). A zero time + error is returned when rev can't be resolved; callers fall back to a status timestamp.

func (*Differ) ForChange

func (d *Differ) ForChange(ctx context.Context, c providers.Change) (providers.Diff, error)

ForChange resolves the diff for a detected Change by cloning its source repo and scoping to the workload's path. With both revisions it diffs FromRev..ToRev; with only ToRev it diffs the change introduced by ToRev (against its parent). ctx bounds the clone + patch so a caller deadline (per-investigation timeout) aborts a hung remote.

When the forward range holds no change to the resource's path it falls back to the newest commit that actually touched the path. This matters on a Flux health-check failure: Flux applies the manifest (advancing lastAppliedRevision to the breaking commit) and only then fails the health gate, so the change is at/behind the applied revision — diffing forward from it misses it entirely (RunLore #239).

func (*Differ) Local

func (d *Differ) Local(ctx context.Context, path, fromRev, toRev, scope string) (providers.Diff, error)

Local diffs two revisions in an already-cloned repository at path. ctx bounds the (potentially expensive) patch computation so a caller deadline is honored.

func (*Differ) Remote

func (d *Differ) Remote(ctx context.Context, url, fromRev, toRev, scope string) (providers.Diff, error)

Remote clones url to disk (auth via the installation token when set) and diffs two revisions. The source may be a remote HTTPS URL or a local path. ctx bounds the clone + patch.

func (*Differ) RemoteFromParent

func (d *Differ) RemoteFromParent(ctx context.Context, url, rev, scope string) (providers.Diff, error)

RemoteFromParent clones url and returns the path-scoped diff of the change introduced by rev (rev against its first parent). A root commit (no parent) yields an empty diff. ctx bounds the clone + patch.

NOTE (perf): does a full (disk) clone per call. When the GitOpsProvider drives this across many changes, add a per-repo clone cache here (see dev/plans note).

func (*Differ) RemoteLastPathChange added in v0.6.1

func (d *Differ) RemoteLastPathChange(ctx context.Context, url, atRev, scope string) (providers.Diff, error)

RemoteLastPathChange clones url and returns the path-scoped diff of the newest commit reachable from atRev that actually modified scope, against its first parent. It is ForChange's fallback when the forward range holds no change to scope (see RunLore #239). Returns an empty diff when scope is empty, no ancestor of atRev touches scope, or the touching commit is a root commit (no parent).

func (*Differ) RevisionsInWindow added in v0.9.0

func (d *Differ) RevisionsInWindow(ctx context.Context, url, atRev, scope string, w providers.TimeWindow, maxRevs int) ([]Revision, error)

RevisionsInWindow clones url and returns the commits reachable from atRev whose committer time falls within w, optionally scoped to a path, newest-first and capped at max. It is what lets Changes honor a TimeWindow: instead of surfacing only the current applied/synced revision, a provider can enumerate every revision that landed in the window and emit a Change per one.

Bounded on purpose (G3 is SAFETY MEDIUM — it changes what "what changed" surfaces to the model): the walk stops once max revisions are collected OR once history predates w.Start, so a wide window on a busy monorepo can't explode the output. A zero-valued window (w.Start.IsZero() && w.End.IsZero()) returns nil so callers fall back to their single-revision behavior. max<=0 also returns nil.

type Revision added in v0.9.0

type Revision struct {
	SHA  string
	When time.Time
}

Revision is one in-window commit on a source repo: its SHA and committer time. It is the unit RevisionsInWindow returns, letting a GitOpsProvider emit one Change per in-window revision instead of only the current applied/synced one (RunLore G3).

Jump to

Keyboard shortcuts

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