Documentation
¶
Index ¶
- Constants
- Variables
- func DefaultExcludePatterns() []string
- func GroupCommits(commits []*ParsedCommit, groups []GroupConfig) map[string][]*GroupedCommit
- func Register(cfg *config.ChangelogGeneratorConfig) error
- func ResetChangelogGenerator()
- func SortedGroupKeys(grouped map[string][]*GroupedCommit) []string
- type ChangelogGenerator
- type ChangelogGeneratorPlugin
- func (p *ChangelogGeneratorPlugin) Description() string
- func (p *ChangelogGeneratorPlugin) GenerateForVersion(version, previousVersion, bumpType string) error
- func (p *ChangelogGeneratorPlugin) GetConfig() *Config
- func (p *ChangelogGeneratorPlugin) IsEnabled() bool
- func (p *ChangelogGeneratorPlugin) Name() string
- func (p *ChangelogGeneratorPlugin) Version() string
- type CommitInfo
- type Config
- type Contributor
- type ContributorsConfig
- type Formatter
- type GenerateResult
- type Generator
- func (g *Generator) GenerateVersionChangelog(version, previousVersion string, commits []CommitInfo) (string, error)
- func (g *Generator) GenerateVersionChangelogWithResult(version, previousVersion string, commits []CommitInfo) GenerateResult
- func (g *Generator) MergeVersionedFiles() error
- func (g *Generator) WriteUnifiedChangelog(newContent string) error
- func (g *Generator) WriteVersionedFile(version, content string) error
- type GitHubFormatter
- type GroupCommitsResult
- type GroupConfig
- type GroupedCommit
- type GroupedFormatter
- type KeepAChangelogFormatter
- type MinimalFormatter
- type NewContributor
- type ParsedCommit
- type RemoteInfo
- type RepositoryConfig
Constants ¶
const DefaultBreakingChangesIcon = "\u26A0\uFE0F" // warning sign ⚠️
DefaultBreakingChangesIcon is the default icon for the breaking changes section.
const DefaultContributorIcon = "\u2764\uFE0F" // red heart ❤️
DefaultContributorIcon is the default icon for the contributors section.
const DefaultNewContributorsIcon = "\U0001F389" // party popper 🎉
DefaultNewContributorsIcon is the default icon for the new contributors section.
Variables ¶
var ( GetCommitsWithMetaFn = getCommitsWithMeta GetRemoteInfoFn = getRemoteInfo GetLatestTagFn = getLatestTag GetContributorsFn = getContributors GetHistoricalContributorsFn = getHistoricalContributors GetNewContributorsFn = getNewContributors )
Mockable functions for testing.
var ( RegisterChangelogGeneratorFn = registerChangelogGenerator GetChangelogGeneratorFn = getChangelogGenerator )
var ConfirmMergeFn = func(message string) (bool, error) { prompter := tui.NewModulePrompt(nil) return prompter.ConfirmOperation(message) }
ConfirmMergeFn is a function variable for prompting user confirmation. Can be overridden in tests.
var DefaultGroupIcons = map[string]string{
"Enhancements": "\U0001F680",
"Fixes": "\U0001FA79",
"Refactors": "\U0001F485",
"Documentation": "\U0001F4D6",
"Performance": "\u26A1",
"Styling": "\U0001F3A8",
"Tests": "\u2705",
"Chores": "\U0001F3E1",
"CI": "\U0001F916",
"Build": "\U0001F4E6",
"Reverts": "\u25C0\uFE0F",
}
DefaultGroupIcons maps default group labels to their icons. These are used when UseDefaultIcons is enabled.
var IsInteractiveFn = tui.IsInteractive
IsInteractiveFn is a function variable for checking if the environment is interactive. Can be overridden in tests.
var KnownProviders = map[string]string{
"github.com": "github",
"gitlab.com": "gitlab",
"codeberg.org": "codeberg",
"gitea.io": "gitea",
"bitbucket.org": "bitbucket",
"sr.ht": "sourcehut",
}
KnownProviders maps hostnames to provider names.
Functions ¶
func DefaultExcludePatterns ¶
func DefaultExcludePatterns() []string
DefaultExcludePatterns returns the default patterns to exclude from changelog.
func GroupCommits ¶
func GroupCommits(commits []*ParsedCommit, groups []GroupConfig) map[string][]*GroupedCommit
GroupCommits groups parsed commits by their type using the configured groups. The order is derived from the position in the groups slice (index) unless explicitly overridden by the Order field (if > 0). If includeNonConventional is true, commits without a type are included in "Other Changes". If false, they are returned in SkippedNonConventional for warning purposes.
func Register ¶
func Register(cfg *config.ChangelogGeneratorConfig) error
Register registers the changelog generator plugin with the given configuration.
func ResetChangelogGenerator ¶
func ResetChangelogGenerator()
ResetChangelogGenerator clears the registered changelog generator (for testing).
func SortedGroupKeys ¶
func SortedGroupKeys(grouped map[string][]*GroupedCommit) []string
SortedGroupKeys returns group labels sorted by their order.
Types ¶
type ChangelogGenerator ¶
type ChangelogGenerator interface {
Name() string
Description() string
Version() string
// GenerateForVersion generates changelog for a specific version bump.
GenerateForVersion(version, previousVersion, bumpType string) error
// IsEnabled returns whether the plugin is enabled.
IsEnabled() bool
// GetConfig returns the plugin configuration.
GetConfig() *Config
}
ChangelogGenerator defines the interface for changelog generation.
type ChangelogGeneratorPlugin ¶
type ChangelogGeneratorPlugin struct {
// contains filtered or unexported fields
}
ChangelogGeneratorPlugin implements the ChangelogGenerator interface.
func NewChangelogGenerator ¶
func NewChangelogGenerator(cfg *Config) (*ChangelogGeneratorPlugin, error)
NewChangelogGenerator creates a new changelog generator plugin.
func (*ChangelogGeneratorPlugin) Description ¶
func (p *ChangelogGeneratorPlugin) Description() string
Description returns the plugin description.
func (*ChangelogGeneratorPlugin) GenerateForVersion ¶
func (p *ChangelogGeneratorPlugin) GenerateForVersion(version, previousVersion, bumpType string) error
GenerateForVersion generates changelog for a version bump.
func (*ChangelogGeneratorPlugin) GetConfig ¶
func (p *ChangelogGeneratorPlugin) GetConfig() *Config
GetConfig returns the plugin configuration.
func (*ChangelogGeneratorPlugin) IsEnabled ¶
func (p *ChangelogGeneratorPlugin) IsEnabled() bool
IsEnabled returns whether the plugin is enabled.
func (*ChangelogGeneratorPlugin) Name ¶
func (p *ChangelogGeneratorPlugin) Name() string
Name returns the plugin name.
func (*ChangelogGeneratorPlugin) Version ¶
func (p *ChangelogGeneratorPlugin) Version() string
Version returns the plugin version.
type CommitInfo ¶
type CommitInfo struct {
Hash string
ShortHash string
Subject string
Author string
AuthorEmail string
}
CommitInfo represents a git commit with metadata.
type Config ¶
type Config struct {
// Enabled controls whether the plugin is active.
Enabled bool
// Mode determines output style: "versioned", "unified", or "both".
Mode string
// Format determines the changelog format: "grouped" or "keepachangelog".
// "grouped" (default): Current behavior with custom group labels
// "keepachangelog": Keep a Changelog specification format
Format string
// ChangesDir is the directory for version-specific changelog files.
ChangesDir string
// ChangelogPath is the path to the unified changelog file.
ChangelogPath string
// HeaderTemplate is the path to a custom header template file.
HeaderTemplate string
// Repository contains git repository settings for link generation.
Repository *RepositoryConfig
// Groups defines commit grouping rules.
Groups []GroupConfig
// ExcludePatterns lists regex patterns for commits to exclude.
ExcludePatterns []string
// IncludeNonConventional includes non-conventional commits in "Other Changes" section.
// When false (default), these commits are skipped with a warning.
IncludeNonConventional bool
// UseDefaultIcons enables default icons for commit groups and contributors.
// When true, predefined icons are applied to default groups and the contributors section.
// User-defined GroupIcons or Contributors.Icon can override specific defaults.
UseDefaultIcons bool
// GroupIcons maps default group labels to icons (used when Groups is empty).
GroupIcons map[string]string
// BreakingChangesIcon is the icon for the breaking changes section header.
// This is used by formatters that have a dedicated breaking changes section.
BreakingChangesIcon string
// Contributors configures the contributors section.
Contributors *ContributorsConfig
// MergeAfter controls when versioned changelog files are merged into the unified changelog.
// Values: "immediate" (merge right after generation), "manual" (no auto-merge, default),
// "prompt" (interactive confirmation, auto-skips in CI/non-interactive environments).
MergeAfter string
}
Config holds the internal configuration for the changelog generator plugin.
func DefaultConfig ¶
func DefaultConfig() *Config
DefaultConfig returns the default changelog generator configuration.
func FromConfigStruct ¶
func FromConfigStruct(cfg *config.ChangelogGeneratorConfig) *Config
FromConfigStruct converts the config package struct to internal config.
type Contributor ¶
type Contributor struct {
Name string
Username string
Email string
Host string // The git host for URL generation
}
Contributor represents a unique contributor.
type ContributorsConfig ¶
type ContributorsConfig struct {
Enabled bool
Format string
Icon string
ShowNewContributors bool
NewContributorsFormat string
NewContributorsIcon string
}
ContributorsConfig configures the contributors section.
type Formatter ¶
type Formatter interface {
// FormatChangelog generates the changelog content for a version.
// It receives the version information, grouped commits, and remote info
// and returns the formatted markdown content.
FormatChangelog(
version string,
previousVersion string,
grouped map[string][]*GroupedCommit,
sortedKeys []string,
remote *RemoteInfo,
) string
}
Formatter defines the interface for changelog formatters. Different formatters can produce different styles of changelogs from the same commit data.
type GenerateResult ¶
type GenerateResult struct {
Content string
SkippedNonConventional []*ParsedCommit
}
GenerateResult contains the generated changelog and any warnings.
type Generator ¶
type Generator struct {
// contains filtered or unexported fields
}
Generator handles changelog content generation.
func NewGenerator ¶
NewGenerator creates a new changelog generator.
func (*Generator) GenerateVersionChangelog ¶
func (g *Generator) GenerateVersionChangelog(version, previousVersion string, commits []CommitInfo) (string, error)
GenerateVersionChangelog generates the changelog content for a version.
func (*Generator) GenerateVersionChangelogWithResult ¶
func (g *Generator) GenerateVersionChangelogWithResult(version, previousVersion string, commits []CommitInfo) GenerateResult
GenerateVersionChangelogWithResult generates the changelog content and returns detailed result.
func (*Generator) MergeVersionedFiles ¶
MergeVersionedFiles merges all versioned changelog files into a unified CHANGELOG.md.
func (*Generator) WriteUnifiedChangelog ¶
WriteUnifiedChangelog writes to the unified CHANGELOG.md file.
func (*Generator) WriteVersionedFile ¶
WriteVersionedFile writes the changelog to a version-specific file.
type GitHubFormatter ¶ added in v0.7.0
type GitHubFormatter struct {
// contains filtered or unexported fields
}
GitHubFormatter implements the GitHub release changelog format. Key features: - Single "What's Changed" section (no grouping by type) - Inline contributor attribution per commit (@username) - PR references inline (in #123) - Simple, flat list style using * instead of -
func (*GitHubFormatter) FormatChangelog ¶ added in v0.7.0
func (f *GitHubFormatter) FormatChangelog( version string, previousVersion string, grouped map[string][]*GroupedCommit, sortedKeys []string, remote *RemoteInfo, ) string
FormatChangelog generates the changelog in GitHub release format.
type GroupCommitsResult ¶
type GroupCommitsResult struct {
Grouped map[string][]*GroupedCommit
SkippedNonConventional []*ParsedCommit
}
GroupCommitsResult contains grouped commits and any skipped non-conventional commits.
func GroupCommitsWithOptions ¶
func GroupCommitsWithOptions(commits []*ParsedCommit, groups []GroupConfig, includeNonConventional bool) GroupCommitsResult
GroupCommitsWithOptions groups commits by configured patterns with options.
type GroupConfig ¶
GroupConfig defines a grouping rule for commits.
func DefaultGroups ¶
func DefaultGroups() []GroupConfig
DefaultGroups returns the default commit grouping rules (git-cliff style). Order is derived from array position (first = 0, second = 1, etc.)
type GroupedCommit ¶
type GroupedCommit struct {
*ParsedCommit
GroupLabel string
GroupIcon string
GroupOrder int
}
GroupedCommit represents a commit with its group assignment.
type GroupedFormatter ¶
type GroupedFormatter struct {
// contains filtered or unexported fields
}
GroupedFormatter implements the default "grouped" changelog format. This formatter groups commits by their configured labels and supports custom icons, compare links, and flexible grouping rules.
func (*GroupedFormatter) FormatChangelog ¶
func (f *GroupedFormatter) FormatChangelog( version string, previousVersion string, grouped map[string][]*GroupedCommit, sortedKeys []string, remote *RemoteInfo, ) string
FormatChangelog generates the changelog in grouped format.
type KeepAChangelogFormatter ¶
type KeepAChangelogFormatter struct {
// contains filtered or unexported fields
}
KeepAChangelogFormatter implements the "Keep a Changelog" format. This formatter follows the Keep a Changelog specification: https://keepachangelog.com/
Key differences from grouped format: - Version header: ## [version] - date (no "v" prefix, brackets around version) - Standard sections: Added, Changed, Deprecated, Removed, Fixed, Security - No custom icons (strict section names)
func (*KeepAChangelogFormatter) FormatChangelog ¶
func (f *KeepAChangelogFormatter) FormatChangelog( version string, previousVersion string, grouped map[string][]*GroupedCommit, sortedKeys []string, remote *RemoteInfo, ) string
FormatChangelog generates the changelog in Keep a Changelog format.
type MinimalFormatter ¶ added in v0.7.0
type MinimalFormatter struct {
// contains filtered or unexported fields
}
MinimalFormatter implements a condensed changelog format using short type abbreviations. Key features: - Version header without date (just `## v1.2.0`) - Abbreviated type prefixes in brackets: [Feat], [Fix], etc. - No sections/grouping - flat list of all commits - No author attribution, no PR links, no commit links - Breaking changes marked with [Breaking] prefix instead of type - Simple `-` bullet points
func (*MinimalFormatter) FormatChangelog ¶ added in v0.7.0
func (f *MinimalFormatter) FormatChangelog( version string, previousVersion string, grouped map[string][]*GroupedCommit, sortedKeys []string, remote *RemoteInfo, ) string
FormatChangelog generates the changelog in minimal format.
type NewContributor ¶
type NewContributor struct {
Contributor
FirstCommit CommitInfo // The commit that introduced this contributor
PRNumber string // PR number if available (extracted from commit message)
}
NewContributor represents a first-time contributor with their first contribution details.
type ParsedCommit ¶
type ParsedCommit struct {
CommitInfo
Type string // feat, fix, docs, etc.
Scope string // Optional scope in parentheses
Description string // The commit description after the colon
Breaking bool // Has breaking change indicator (! or BREAKING CHANGE footer)
PRNumber string // Extracted PR/MR number if present
}
ParsedCommit represents a fully parsed conventional commit.
func FilterCommits ¶
func FilterCommits(commits []*ParsedCommit, excludePatterns []string) []*ParsedCommit
FilterCommits filters out commits matching exclude patterns.
func ParseCommits ¶
func ParseCommits(commits []CommitInfo) []*ParsedCommit
ParseCommits parses a slice of CommitInfo into ParsedCommits.
func ParseConventionalCommit ¶
func ParseConventionalCommit(commit *CommitInfo) *ParsedCommit
ParseConventionalCommit parses a commit message into its components. Returns nil if the commit doesn't follow conventional commit format.
type RemoteInfo ¶
type RemoteInfo struct {
Provider string // github, gitlab, codeberg, gitea, bitbucket, custom
Host string // e.g., github.com, gitlab.com, codeberg.org
Owner string
Repo string
}
RemoteInfo holds parsed git remote information. Supports multiple providers: github, gitlab, codeberg, gitea, bitbucket, etc.
type RepositoryConfig ¶
type RepositoryConfig struct {
// Provider is the git hosting provider: github, gitlab, codeberg, gitea, bitbucket, custom.
Provider string
// Host is the git server hostname (e.g., "github.com", "gitlab.com").
Host string
// Owner is the repository owner/organization.
Owner string
// Repo is the repository name.
Repo string
// AutoDetect enables automatic detection from git remote.
AutoDetect bool
}
RepositoryConfig holds git repository settings for changelog links. Supports multiple providers: github, gitlab, codeberg, gitea, bitbucket, custom.