matching

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Mar 13, 2026 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AppDiff

type AppDiff struct {
	OldName       string // Name in base branch (empty if added)
	NewName       string // Name in target branch (empty if deleted)
	OldSourcePath string // Source path in base branch
	NewSourcePath string // Source path in target branch
	Action        DiffAction
	Resources     []ResourceDiff // Per-resource diffs
	AddedLines    int
	DeletedLines  int
	EmptyReason   EmptyReason // Why Resources is empty (only meaningful when len(Resources) == 0)
}

AppDiff represents the diff output for a single application pair

func GenerateAppDiffs

func GenerateAppDiffs(
	baseApps, targetApps []extract.ExtractedApp,
	contextLines uint,
	ignorePattern *string,
	ignoreResourceRules []resource_filter.IgnoreResourceRule,
) ([]AppDiff, error)

GenerateAppDiffs uses similarity matching to generate diffs between base and target apps. This replaces the ID-based matching with content-based matching.

func (*AppDiff) ChangeStats

func (d *AppDiff) ChangeStats() string

ChangeStats returns a formatted string showing +/- line counts

func (*AppDiff) HasContent

func (d *AppDiff) HasContent() bool

HasContent returns true if the diff has any resource content to show

func (*AppDiff) PrettyName

func (d *AppDiff) PrettyName() string

PrettyName returns a display name for the diff

func (*AppDiff) PrettyPath

func (d *AppDiff) PrettyPath() string

PrettyPath returns a display path for the diff

type DiffAction

type DiffAction int

DiffAction represents the type of change

const (
	ActionAdded DiffAction = iota
	ActionDeleted
	ActionModified
	ActionUnchanged
)

func (DiffAction) String

func (a DiffAction) String() string

type DiffResult

type DiffResult struct {
	Content      string // The formatted diff content
	AddedLines   int    // Number of lines added
	DeletedLines int    // Number of lines deleted
}

DiffResult contains the diff output and statistics for a resource pair

type EmptyReason

type EmptyReason int

EmptyReason describes why an application section has no resource diffs

const (
	EmptyReasonNone        EmptyReason = iota // not empty - has resources
	EmptyReasonNoResources                    // application genuinely rendered no resources
	EmptyReasonHiddenDiff                     // diff hidden by --hide-deleted-app-diff
)

type Pair

type Pair struct {
	Base   *extract.ExtractedApp // nil if app was added in target
	Target *extract.ExtractedApp // nil if app was deleted in target
}

Pair represents a matched pair of ExtractedApps from base and target branches

func MatchApps

func MatchApps(baseApps, targetApps []extract.ExtractedApp) []Pair

MatchApps finds the best pairing between base and target ExtractedApps. It uses a three-phase matching strategy:

  1. Match by exact identity (name + source path) - strongest signal.
  2. Match remaining by exact name only - catches apps whose source path changed but name stayed the same. This also ensures deterministic results for ApplicationSet-generated apps that produce nearly identical resources.
  3. Match remaining by content similarity - handles renames, moves, etc.

Returns a list of pairs where each pair contains matching base and target apps. If an app only exists in base, Target will be nil (deleted). If an app only exists in target, Base will be nil (added).

func (*Pair) ChangedResources

func (p *Pair) ChangedResources() []ResourcePair

ChangedResources returns only the resources that differ between base and target within this app pair. Identical resources are filtered out.

type ResourceDiff

type ResourceDiff struct {
	Kind         string
	OldKind      string // empty if unchanged or added/deleted
	Name         string
	OldName      string // empty if unchanged or added/deleted
	Namespace    string
	OldNamespace string // empty if unchanged or added/deleted
	Content      string // diff text (with +/-/space prefixes)
	AddedLines   int
	DeletedLines int
	IsSkipped    bool // true if resource matched an ignore rule
}

ResourceDiff represents the diff output for a single resource within an application

func (*ResourceDiff) Header

func (r *ResourceDiff) Header() string

Header returns a display header for the resource. Format: "Kind: namespace/Name" with arrows for changes:

  • Kind change: "OldKind → NewKind: namespace/Name"
  • Name change: "Kind: namespace/OldName → namespace/NewName"
  • Namespace change: "Kind: oldNs/Name → newNs/Name"
  • Cluster-scoped: "Kind: Name" (no namespace prefix)

type ResourcePair

type ResourcePair struct {
	Base   *unstructured.Unstructured // nil if resource was added
	Target *unstructured.Unstructured // nil if resource was deleted
}

ResourcePair represents a matched pair of Kubernetes resources within an app pair

func (*ResourcePair) Diff

func (rp *ResourcePair) Diff(contextLines uint) (DiffResult, error)

Diff generates a unified diff between the base and target resources. Returns a DiffResult with the formatted diff and line statistics.

For added resources (Base is nil), shows all lines as additions. For deleted resources (Target is nil), shows all lines as deletions. For modified resources, shows a unified diff with context.

Jump to

Keyboard shortcuts

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