mutate

package
v0.32.2 Latest Latest
Warning

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

Go to latest
Published: Jun 26, 2026 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RegisterMutator

func RegisterMutator(name string, m Mutator)

RegisterMutator adds a mutator to the registry

func ValidMutationTypes

func ValidMutationTypes() []string

ValidMutationTypes returns the list of registered mutation type names

Types

type MutationConfig

type MutationConfig struct {
	Rules []MutationRule `json:"mutations" yaml:"mutations"`
}

MutationConfig holds the full mutation configuration

func LoadConfig

func LoadConfig(path string) (*MutationConfig, error)

LoadConfig reads a mutation config from a YAML or JSON file

type MutationResult

type MutationResult struct {
	Rule     MutationRule `json:"rule" yaml:"rule"`
	OldValue string       `json:"old_value" yaml:"old_value"`
	NewValue string       `json:"new_value" yaml:"new_value"`
	Applied  bool         `json:"applied" yaml:"applied"`
	Error    string       `json:"error,omitempty" yaml:"error,omitempty"`
	Diff     string       `json:"diff,omitempty" yaml:"diff,omitempty"`
}

MutationResult captures the outcome of a single mutation

func ApplyMutations

func ApplyMutations(repoRoot string, config *MutationConfig, version string, dryRun bool) ([]MutationResult, error)

ApplyMutations executes all mutation rules against files in repoRoot if dryRun is true, computes results without writing to disk

func DryRunMutations

func DryRunMutations(repoRoot string, config *MutationConfig, version string) ([]MutationResult, error)

DryRunMutations is a convenience wrapper for ApplyMutations with dryRun=true

type MutationRule

type MutationRule struct {
	Path     string `json:"path" yaml:"path"`                           // file path relative to repo root
	Type     string `json:"type" yaml:"type"`                           // jsonPath, yamlPath, tomlKey, regexReplace, exec
	Field    string `json:"field" yaml:"field"`                         // path expression (dot-notation, regex pattern, or shell command)
	Replace  string `json:"replace,omitempty" yaml:"replace,omitempty"` // replacement template (for regex)
	Global   bool   `json:"global,omitempty" yaml:"global,omitempty"`   // replace all matches (regex only)
	RepoRoot string `json:"-" yaml:"-"`                                 // runtime-only: set by engine, not serialized
}

MutationRule defines a single file mutation to perform

type Mutator

type Mutator interface {
	// Apply performs the mutation on file content, returning updated content and result
	Apply(content []byte, field string, newValue string, rule MutationRule) ([]byte, *MutationResult, error)
}

Mutator is the interface each file-type mutator implements

func GetMutator

func GetMutator(mutationType string) (Mutator, error)

GetMutator returns the mutator for the given type name

Jump to

Keyboard shortcuts

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