changeentry

package
v0.0.0-...-03ca8a1 Latest Latest
Warning

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

Go to latest
Published: Mar 30, 2026 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ExitCodeGeneral    = 1
	ExitCodeValidation = 2
	ExitCodeConflict   = 3
)
View Source
const UserConfigEnvVar = "CHAGG_USER_CONFIG"

Variables

View Source
var ConfigFileNames = []string{".chagg.yaml", ".chagg.yml", "chagg.yml"}

Functions

func BuildChangeFilePath

func BuildChangeFilePath(changesDir string, targetArg string) (string, error)

func BumpFlagUsage

func BumpFlagUsage() string

BumpFlagUsage returns the usage string for the --bump CLI flag.

func BumpPrompt

func BumpPrompt() string

BumpPrompt returns the interactive prompt string for the bump override field.

func CreateChange

func CreateChange(module ModuleConfig, targetArg string, params Params, input io.Reader, output io.Writer, interactive bool) (string, error)

CreateChange creates a new change entry file under module.ChangesDir. The caller is responsible for ensuring the directory already exists.

func RenderEntry

func RenderEntry(entry Entry) (string, error)

func ResolveChangesDirectory

func ResolveChangesDirectory(startPath string) (string, error)

func ResolveModulesForChangesDirs

func ResolveModulesForChangesDirs(repoRoot string, changesDirs []string) (map[string]ModuleConfig, error)

ResolveModulesForChangesDirs maps every discovered changes directory to a fully resolved ModuleConfig.

Types

type BumpLevel

type BumpLevel string

BumpLevel represents an explicit semver bump level override for a change entry. An empty BumpLevel means "use the type-based default".

const (
	BumpLevelMajor BumpLevel = "major"
	BumpLevelMinor BumpLevel = "minor"
	BumpLevelPatch BumpLevel = "patch"
)

func NormalizeBumpLevel

func NormalizeBumpLevel(value string) (BumpLevel, error)

NormalizeBumpLevel validates and normalises a bump level string. An empty string is accepted and returns an empty BumpLevel (use type default).

type ChangeType

type ChangeType string

ChangeType is the canonical identifier of a change type (e.g. "feature", "fix").

const (
	ChangeTypeFeature  ChangeType = "feature"
	ChangeTypeFix      ChangeType = "fix"
	ChangeTypeRemoval  ChangeType = "removal"
	ChangeTypeSecurity ChangeType = "security"
	ChangeTypeDocs     ChangeType = "docs"
	ChangeTypeChore    ChangeType = "chore"
)

Well-known built-in type IDs.

func InferTypeFromFilename

func InferTypeFromFilename(path string, registry TypeRegistry) (ChangeType, error)

InferTypeFromFilename resolves a change type from the filename prefix using the provided type registry. Accepted patterns are case-insensitive and include one or two underscores, e.g. feat__login.md, Feat_login.md.

type CheckResult

type CheckResult struct {
	Module ModuleConfig
	Path   string
	Errors []error
}

CheckResult holds the validation outcome for a single change entry file.

func CheckAllChangesDirs

func CheckAllChangesDirs(startPath string) ([]CheckResult, error)

CheckAllChangesDirs locates every ".changes" directory reachable from startPath (by first finding the git root) and validates all change entries inside them.

func CheckChangesDir

func CheckChangesDir(changesDir string, module ModuleConfig) ([]CheckResult, error)

CheckChangesDir validates all ".md" files found recursively inside changesDir. Each file is parsed and its validation errors are collected in CheckResult. Files that resolve (via symlinks) to a path outside changesDir are skipped with a warning.

func (CheckResult) Valid

func (r CheckResult) Valid() bool

Valid reports whether the entry has no validation errors.

type CodedError

type CodedError interface {
	error
	ExitCode() int
}

type ConfigIO

type ConfigIO interface {
	// ReadUserConfig reads the user-level config. Returns nil if absent.
	ReadUserConfig() (*RawConfig, error)
	// WriteUserConfig persists cfg to the user config file, creating parent dirs as needed.
	WriteUserConfig(cfg *RawConfig) error
	// UserConfigPath returns the resolved path to the user config file (may not exist).
	UserConfigPath() (string, error)
	// ReadRepoConfig reads the repo-level config. Returns (nil, "", nil) if absent.
	ReadRepoConfig(repoRoot string) (*RawConfig, string, error)
	// WriteRepoConfig persists cfg to the repo config file (overwrites existing or creates .chagg.yaml).
	// Returns the filename (base name only) that was written.
	WriteRepoConfig(repoRoot string, cfg *RawConfig) (string, error)
}

ConfigIO abstracts reading and writing of chagg configuration files. The default implementation (FileConfigIO) uses the real filesystem. Tests can supply a MockConfigIO to avoid filesystem I/O entirely.

func NewFileConfigIO

func NewFileConfigIO() ConfigIO

NewFileConfigIO returns a ConfigIO backed by the real filesystem.

type ConflictError

type ConflictError struct {
	Message string
}

func NewConflictError

func NewConflictError(message string) *ConflictError

func (*ConflictError) Error

func (e *ConflictError) Error() string

func (*ConflictError) ExitCode

func (e *ConflictError) ExitCode() int

type Defaults

type Defaults struct {
	Audience  []string // applied when an entry omits the audience: field
	Rank      int      // default rank for new entries
	Component []string // applied when an entry omits the component: field
}

Defaults holds resolved entry-field defaults for a module. A nil slice means "no default configured at this level". Rank defaults to 0 when not configured.

type Entry

type Entry struct {
	Type      ChangeType
	Bump      BumpLevel
	Component []string
	Audience  []string
	Rank      int
	Issue     []string
	Release   string
	Body      string
}

func ParseEntry

func ParseEntry(content string, path string, module ModuleConfig) (Entry, []error)

ParseEntry parses the content of a change entry file using the type registry and defaults from module. It returns the parsed Entry and any validation errors. If the YAML structure is invalid, a single error is returned.

type FileConfigIO

type FileConfigIO struct{}

FileConfigIO is the production ConfigIO that reads/writes the real filesystem.

func (FileConfigIO) ReadRepoConfig

func (FileConfigIO) ReadRepoConfig(repoRoot string) (*RawConfig, string, error)

func (FileConfigIO) ReadUserConfig

func (FileConfigIO) ReadUserConfig() (*RawConfig, error)

func (FileConfigIO) UserConfigPath

func (FileConfigIO) UserConfigPath() (string, error)

func (FileConfigIO) WriteRepoConfig

func (FileConfigIO) WriteRepoConfig(repoRoot string, cfg *RawConfig) (string, error)

func (FileConfigIO) WriteUserConfig

func (FileConfigIO) WriteUserConfig(cfg *RawConfig) error

type GitWritePolicy

type GitWritePolicy struct {
	Enabled     bool
	Add         bool
	ReleaseTag  bool
	ReleasePush bool
}

GitWritePolicy controls which git write operations chagg is allowed to perform.

func (GitWritePolicy) AllowsAdd

func (p GitWritePolicy) AllowsAdd() bool

func (GitWritePolicy) AllowsReleasePush

func (p GitWritePolicy) AllowsReleasePush() bool

func (GitWritePolicy) AllowsReleaseTag

func (p GitWritePolicy) AllowsReleaseTag() bool

type MockConfigIO

type MockConfigIO struct {
	// Inputs
	UserCfg    *RawConfig
	UserCfgErr error
	RepoCfg    *RawConfig
	RepoName   string // defaults to ".chagg.yaml" when empty
	RepoCfgErr error
	UserPath   string // defaults to "/mock/home/.config/chagg/config.yaml"

	// Outputs (populated by Write calls)
	WrittenUserCfg *RawConfig
	WrittenRepoCfg *RawConfig
	WriteUserErr   error
	WriteRepoErr   error
}

MockConfigIO implements ConfigIO with in-memory storage, suitable for unit tests. All fields are exported so tests can set up preconditions and inspect results directly.

func (*MockConfigIO) ReadRepoConfig

func (m *MockConfigIO) ReadRepoConfig(repoRoot string) (*RawConfig, string, error)

func (*MockConfigIO) ReadUserConfig

func (m *MockConfigIO) ReadUserConfig() (*RawConfig, error)

func (*MockConfigIO) UserConfigPath

func (m *MockConfigIO) UserConfigPath() (string, error)

func (*MockConfigIO) WriteRepoConfig

func (m *MockConfigIO) WriteRepoConfig(repoRoot string, cfg *RawConfig) (string, error)

func (*MockConfigIO) WriteUserConfig

func (m *MockConfigIO) WriteUserConfig(cfg *RawConfig) error

type ModuleConfig

type ModuleConfig struct {
	Name       string
	ChangesDir string
	TagPrefix  string
	Defaults   Defaults
	Types      TypeRegistry
	GitWrite   GitWritePolicy
	Release    ReleasePolicy
}

ModuleConfig is the fully resolved configuration for a single changes module.

func ResolveModuleForChangesDir

func ResolveModuleForChangesDir(repoRoot string, changesDir string) (ModuleConfig, error)

ResolveModuleForChangesDir returns the fully resolved ModuleConfig for the target changes directory by merging: code defaults → user config → repo config → module-level config.

type Params

type Params struct {
	Type         string
	TypeSet      bool
	Bump         string
	BumpSet      bool
	Component    string
	ComponentSet bool
	Audience     string
	AudienceSet  bool
	Rank         int
	RankSet      bool
	Issue        string
	IssueSet     bool
	Release      string
	ReleaseSet   bool
	Body         string
	BodySet      bool
	Defaults     Defaults
}

Params carries CLI-provided values for a new change entry. Defaults carries the resolved per-module defaults used when a field is not explicitly set.

type RawConfig

type RawConfig struct {
	Defaults RawDefaults      `yaml:"defaults,omitempty"`
	Git      RawGit           `yaml:"git,omitempty"`
	Types    []rawTypeEntry   `yaml:"types,omitempty"`
	Modules  []RawModule      `yaml:"modules,omitempty"`
	Release  RawReleasePolicy `yaml:"release,omitempty"`
}

RawConfig is the YAML schema shared by both the user config and the repo config. The Modules field is only meaningful in the repo config.

type RawDefaults

type RawDefaults struct {
	Audience  StringListConfig `yaml:"audience,omitempty"`
	Rank      *int             `yaml:"rank,omitempty"`
	Component StringListConfig `yaml:"component,omitempty"`
}

type RawGit

type RawGit struct {
	Write RawGitWrite `yaml:"write,omitempty"`
}

type RawGitWrite

type RawGitWrite struct {
	Allow      *bool          `yaml:"allow,omitempty"`
	Operations RawGitWriteOps `yaml:"operations,omitempty"`
}

type RawGitWriteOps

type RawGitWriteOps struct {
	AddChange        *bool `yaml:"add-change,omitempty"`
	CreateReleaseTag *bool `yaml:"create-release-tag,omitempty"`
	PushReleaseTag   *bool `yaml:"push-release-tag,omitempty"`
}

type RawModule

type RawModule struct {
	Name       string           `yaml:"name,omitempty"`
	ChangesDir string           `yaml:"changes-dir,omitempty"`
	TagPrefix  string           `yaml:"tag-prefix,omitempty"`
	Defaults   RawDefaults      `yaml:"defaults,omitempty"`
	Types      []rawTypeEntry   `yaml:"types,omitempty"`
	Release    RawReleasePolicy `yaml:"release,omitempty"`
}

RawModule is a single entry in the repo config's modules list.

type RawReleasePolicy

type RawReleasePolicy struct {
	VPrefix   string `yaml:"v-prefix,omitempty"`
	AliasTags string `yaml:"alias-tags,omitempty"`
}

RawReleasePolicy is the YAML schema for the release: config section.

type ReleasePolicy

type ReleasePolicy struct {
	VPrefix   string // "auto" | "always" | "never"
	AliasTags string // "auto" | "always" | "never"
}

ReleasePolicy controls how release tags are formatted and which alias tags are created.

type StringListConfig

type StringListConfig []string

StringListConfig is a YAML type that accepts either a scalar string or a sequence of strings, and stays nil when the field is absent.

func (*StringListConfig) UnmarshalYAML

func (s *StringListConfig) UnmarshalYAML(node *yaml.Node) error

type TypeDefinition

type TypeDefinition struct {
	ID          ChangeType
	Aliases     []string // lower-cased; does NOT include the ID itself
	Title       string
	DefaultBump BumpLevel
	Order       int
}

TypeDefinition describes a change type: its canonical ID, recognised case-insensitive aliases, the section title in generated changelogs, the default SemVer bump level, and the display order (lower = earlier).

type TypeRegistry

type TypeRegistry struct {
	// contains filtered or unexported fields
}

TypeRegistry is an immutable, resolved set of change types built from the layered configuration. Always create via DefaultTypeRegistry() or buildTypeRegistry(); the zero value has an empty lookup map and will only find types via the built-in fallback in DefaultBumpLevel.

func DefaultTypeRegistry

func DefaultTypeRegistry() TypeRegistry

DefaultTypeRegistry returns a registry containing only the built-in types.

func (TypeRegistry) DefaultBumpLevel

func (r TypeRegistry) DefaultBumpLevel(ct ChangeType) BumpLevel

DefaultBumpLevel returns the default bump level for the given change type. Falls back to the built-in definitions when the type is not in this registry, so that a zero-value registry still returns sensible defaults for built-in types.

func (TypeRegistry) Definitions

func (r TypeRegistry) Definitions() []TypeDefinition

Definitions returns the type definitions in display order. Falls back to built-in definitions when the registry is uninitialized.

func (TypeRegistry) NormalizeType

func (r TypeRegistry) NormalizeType(value string) (ChangeType, error)

NormalizeType resolves a raw string (alias or ID) to the canonical ChangeType. When the registry is uninitialized (zero value), it falls back to the built-in types.

func (TypeRegistry) TypeFlagUsage

func (r TypeRegistry) TypeFlagUsage() string

TypeFlagUsage returns the --type flag usage string.

func (TypeRegistry) TypeNames

func (r TypeRegistry) TypeNames() []string

TypeNames returns the canonical IDs of all registered types in display order. Falls back to built-in type names when the registry is uninitialized.

func (TypeRegistry) TypePrompt

func (r TypeRegistry) TypePrompt() string

TypePrompt returns the interactive prompt string for the type field.

type ValidationError

type ValidationError struct {
	Field   string
	Message string
}

func NewValidationError

func NewValidationError(field string, message string) *ValidationError

func (*ValidationError) Error

func (e *ValidationError) Error() string

func (*ValidationError) ExitCode

func (e *ValidationError) ExitCode() int

Jump to

Keyboard shortcuts

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