Documentation
¶
Index ¶
- Variables
- func DeleteTag(name string) error
- func FormatMessage(template string, data TemplateData) string
- func InterpolatePrefix(prefix, modulePath string) string
- func ListTags(pattern string) ([]string, error)
- type Config
- type MockGitCommitOperations
- type MockGitTagOperations
- func (m *MockGitTagOperations) CreateAnnotatedTag(ctx context.Context, name, message string) error
- func (m *MockGitTagOperations) CreateLightweightTag(ctx context.Context, name string) error
- func (m *MockGitTagOperations) CreateSignedTag(ctx context.Context, name, message, keyID string) error
- func (m *MockGitTagOperations) DeleteRemoteTag(ctx context.Context, name string) error
- func (m *MockGitTagOperations) DeleteTag(ctx context.Context, name string) error
- func (m *MockGitTagOperations) GetLatestTag(ctx context.Context) (string, error)
- func (m *MockGitTagOperations) ListTags(ctx context.Context, pattern string) ([]string, error)
- func (m *MockGitTagOperations) PushTag(ctx context.Context, name string) error
- func (m *MockGitTagOperations) TagExists(ctx context.Context, name string) (bool, error)
- type NowFunc
- type OSGitCommitOperations
- type OSGitTagOperations
- func (g *OSGitTagOperations) CreateAnnotatedTag(ctx context.Context, name, message string) error
- func (g *OSGitTagOperations) CreateLightweightTag(ctx context.Context, name string) error
- func (g *OSGitTagOperations) CreateSignedTag(ctx context.Context, name, message, keyID string) error
- func (g *OSGitTagOperations) DeleteRemoteTag(ctx context.Context, name string) error
- func (g *OSGitTagOperations) DeleteTag(ctx context.Context, name string) error
- func (g *OSGitTagOperations) GetLatestTag(ctx context.Context) (string, error)
- func (g *OSGitTagOperations) ListTags(ctx context.Context, pattern string) ([]string, error)
- func (g *OSGitTagOperations) PushTag(ctx context.Context, name string) error
- func (g *OSGitTagOperations) TagExists(ctx context.Context, name string) (bool, error)
- type TagManager
- type TagManagerPlugin
- func (p *TagManagerPlugin) CommitChanges(version semver.SemVersion, extraFiles []string) error
- func (p *TagManagerPlugin) CreateTag(version semver.SemVersion, message string) error
- func (p *TagManagerPlugin) Description() string
- func (p *TagManagerPlugin) FormatTagMessage(version semver.SemVersion) string
- func (p *TagManagerPlugin) FormatTagName(version semver.SemVersion) string
- func (p *TagManagerPlugin) GetConfig() *Config
- func (p *TagManagerPlugin) GetLatestTag() (semver.SemVersion, error)
- func (p *TagManagerPlugin) IsAutoCreateEnabled() bool
- func (p *TagManagerPlugin) Name() string
- func (p *TagManagerPlugin) SetPrefix(prefix string)
- func (p *TagManagerPlugin) ShouldCreateTag(version semver.SemVersion) bool
- func (p *TagManagerPlugin) TagExists(version semver.SemVersion) (bool, error)
- func (p *TagManagerPlugin) ValidateTagAvailable(version semver.SemVersion) error
- func (p *TagManagerPlugin) Version() string
- type TemplateData
Constants ¶
This section is empty.
Variables ¶
var TemplatePlaceholders = []string{
"{version}",
"{tag}",
"{prefix}",
"{module_path}",
"{date}",
"{major}",
"{minor}",
"{patch}",
"{prerelease}",
"{build}",
}
TemplatePlaceholders defines the available placeholders for message templates.
Functions ¶
func FormatMessage ¶ added in v0.7.0
func FormatMessage(template string, data TemplateData) string
FormatMessage applies template substitution to a message template.
func InterpolatePrefix ¶ added in v0.13.0
InterpolatePrefix resolves {module_path} in a prefix string. For root modules (empty modulePath), a pattern like "{module_path}/v" becomes "/v" after replacement, then the leading "/" is trimmed to "v". The modulePath "." is treated as empty (root module).
Types ¶
type Config ¶
type Config struct {
// Enabled controls whether the plugin is active.
Enabled bool
// AutoCreate automatically creates tags after version bumps.
AutoCreate bool
// Prefix is the tag prefix (default: "v").
Prefix string
// Annotate creates annotated tags instead of lightweight tags.
Annotate bool
// Push automatically pushes tags to remote after creation.
Push bool
// TagPrereleases controls whether tags are created for pre-release versions.
// When false, tags are only created for stable releases (major/minor/patch).
// Default: false (opt-in for pre-release tagging).
TagPrereleases bool
// Sign creates GPG-signed tags using git tag -s.
// Requires git to be configured with a GPG signing key.
// Default: false.
Sign bool
// SigningKey specifies the GPG key ID to use for signing.
// If empty, git uses the default signing key from user.signingkey config.
// Only used when Sign is true.
SigningKey string
// MessageTemplate is a template for the tag message.
// Supports placeholders: {version}, {tag}, {prefix}, {date}, {major}, {minor}, {patch}, {prerelease}, {build}
// Default: "Release {version}" for annotated/signed tags.
MessageTemplate string
// CommitMessageTemplate is a template for the commit message created before tagging.
// Only used when AutoCreate is true. Supports the same placeholders as MessageTemplate.
// Default: "chore(release): {tag}"
CommitMessageTemplate string
}
Config holds configuration for the tag manager plugin.
func DefaultConfig ¶
func DefaultConfig() *Config
DefaultConfig returns the default tag manager configuration.
type MockGitCommitOperations ¶ added in v0.11.3
type MockGitCommitOperations struct {
StageFilesFn func(ctx context.Context, files ...string) error
CommitFn func(ctx context.Context, message string) error
GetModifiedFilesFn func(ctx context.Context) ([]string, error)
}
MockGitCommitOperations is a mock implementation of core.GitCommitOperations for testing.
func (*MockGitCommitOperations) Commit ¶ added in v0.11.3
func (m *MockGitCommitOperations) Commit(ctx context.Context, message string) error
Commit implements core.GitCommitOperations.
func (*MockGitCommitOperations) GetModifiedFiles ¶ added in v0.11.3
func (m *MockGitCommitOperations) GetModifiedFiles(ctx context.Context) ([]string, error)
GetModifiedFiles implements core.GitCommitOperations.
func (*MockGitCommitOperations) StageFiles ¶ added in v0.11.3
func (m *MockGitCommitOperations) StageFiles(ctx context.Context, files ...string) error
StageFiles implements core.GitCommitOperations.
type MockGitTagOperations ¶ added in v0.7.0
type MockGitTagOperations struct {
CreateAnnotatedTagFn func(ctx context.Context, name, message string) error
CreateLightweightTagFn func(ctx context.Context, name string) error
CreateSignedTagFn func(ctx context.Context, name, message, keyID string) error
TagExistsFn func(ctx context.Context, name string) (bool, error)
GetLatestTagFn func(ctx context.Context) (string, error)
PushTagFn func(ctx context.Context, name string) error
ListTagsFn func(ctx context.Context, pattern string) ([]string, error)
DeleteTagFn func(ctx context.Context, name string) error
DeleteRemoteTagFn func(ctx context.Context, name string) error
}
MockGitTagOperations is a mock implementation of core.GitTagOperations for testing.
func (*MockGitTagOperations) CreateAnnotatedTag ¶ added in v0.7.0
func (m *MockGitTagOperations) CreateAnnotatedTag(ctx context.Context, name, message string) error
CreateAnnotatedTag implements core.GitTagOperations.
func (*MockGitTagOperations) CreateLightweightTag ¶ added in v0.7.0
func (m *MockGitTagOperations) CreateLightweightTag(ctx context.Context, name string) error
CreateLightweightTag implements core.GitTagOperations.
func (*MockGitTagOperations) CreateSignedTag ¶ added in v0.7.0
func (m *MockGitTagOperations) CreateSignedTag(ctx context.Context, name, message, keyID string) error
CreateSignedTag implements core.GitTagOperations.
func (*MockGitTagOperations) DeleteRemoteTag ¶ added in v0.7.0
func (m *MockGitTagOperations) DeleteRemoteTag(ctx context.Context, name string) error
DeleteRemoteTag implements core.GitTagOperations.
func (*MockGitTagOperations) DeleteTag ¶ added in v0.7.0
func (m *MockGitTagOperations) DeleteTag(ctx context.Context, name string) error
DeleteTag implements core.GitTagOperations.
func (*MockGitTagOperations) GetLatestTag ¶ added in v0.7.0
func (m *MockGitTagOperations) GetLatestTag(ctx context.Context) (string, error)
GetLatestTag implements core.GitTagOperations.
type NowFunc ¶ added in v0.12.1
NowFunc returns the current time. Used to allow deterministic testing.
type OSGitCommitOperations ¶ added in v0.11.3
type OSGitCommitOperations struct {
// contains filtered or unexported fields
}
OSGitCommitOperations implements core.GitCommitOperations using actual git commands.
func NewOSGitCommitOperations ¶ added in v0.11.3
func NewOSGitCommitOperations() *OSGitCommitOperations
NewOSGitCommitOperations creates a new OSGitCommitOperations with the default exec.CommandContext.
func (*OSGitCommitOperations) Commit ¶ added in v0.11.3
func (g *OSGitCommitOperations) Commit(ctx context.Context, message string) error
func (*OSGitCommitOperations) GetModifiedFiles ¶ added in v0.11.3
func (g *OSGitCommitOperations) GetModifiedFiles(ctx context.Context) ([]string, error)
func (*OSGitCommitOperations) StageFiles ¶ added in v0.11.3
func (g *OSGitCommitOperations) StageFiles(ctx context.Context, files ...string) error
type OSGitTagOperations ¶
type OSGitTagOperations struct {
// contains filtered or unexported fields
}
OSGitTagOperations implements core.GitTagOperations using actual git commands.
func NewOSGitTagOperations ¶
func NewOSGitTagOperations() *OSGitTagOperations
NewOSGitTagOperations creates a new OSGitTagOperations with the default exec.CommandContext.
func (*OSGitTagOperations) CreateAnnotatedTag ¶
func (g *OSGitTagOperations) CreateAnnotatedTag(ctx context.Context, name, message string) error
func (*OSGitTagOperations) CreateLightweightTag ¶
func (g *OSGitTagOperations) CreateLightweightTag(ctx context.Context, name string) error
func (*OSGitTagOperations) CreateSignedTag ¶ added in v0.7.0
func (g *OSGitTagOperations) CreateSignedTag(ctx context.Context, name, message, keyID string) error
func (*OSGitTagOperations) DeleteRemoteTag ¶ added in v0.7.0
func (g *OSGitTagOperations) DeleteRemoteTag(ctx context.Context, name string) error
func (*OSGitTagOperations) DeleteTag ¶ added in v0.7.0
func (g *OSGitTagOperations) DeleteTag(ctx context.Context, name string) error
func (*OSGitTagOperations) GetLatestTag ¶
func (g *OSGitTagOperations) GetLatestTag(ctx context.Context) (string, error)
type TagManager ¶
type TagManager interface {
Name() string
Description() string
Version() string
// CreateTag creates a git tag for the given version.
CreateTag(version semver.SemVersion, message string) error
// TagExists checks if a tag for the given version already exists.
TagExists(version semver.SemVersion) (bool, error)
// GetLatestTag returns the latest semver tag from git.
GetLatestTag() (semver.SemVersion, error)
// ValidateTagAvailable ensures a tag can be created for the version.
ValidateTagAvailable(version semver.SemVersion) error
// FormatTagName formats a version as a tag name.
FormatTagName(version semver.SemVersion) string
// IsAutoCreateEnabled returns whether the plugin is enabled with auto-create on.
IsAutoCreateEnabled() bool
// GetConfig returns the plugin configuration.
GetConfig() *Config
// CommitChanges stages modified files and creates a commit before tagging.
CommitChanges(version semver.SemVersion, extraFiles []string) error
}
TagManager defines the interface for git tag operations.
type TagManagerPlugin ¶
type TagManagerPlugin struct {
// contains filtered or unexported fields
}
TagManagerPlugin implements the TagManager interface.
func NewTagManager ¶
func NewTagManager(cfg *Config) *TagManagerPlugin
NewTagManager creates a new tag manager plugin with the given configuration. Uses the default OSGitTagOperations and OSGitCommitOperations for git operations.
func NewTagManagerWithOps ¶ added in v0.7.0
func NewTagManagerWithOps(cfg *Config, gitOps core.GitTagOperations, commitOps core.GitCommitOperations) *TagManagerPlugin
NewTagManagerWithOps creates a new tag manager plugin with custom git operations. This constructor enables dependency injection for testing.
func (*TagManagerPlugin) CommitChanges ¶ added in v0.11.3
func (p *TagManagerPlugin) CommitChanges(version semver.SemVersion, extraFiles []string) error
CommitChanges stages modified files and creates a commit before tagging. It detects modified files via git status plus any explicitly provided extraFiles, then commits with a message formatted from the CommitMessageTemplate.
func (*TagManagerPlugin) CreateTag ¶
func (p *TagManagerPlugin) CreateTag(version semver.SemVersion, message string) error
CreateTag creates a git tag for the given version.
func (*TagManagerPlugin) Description ¶
func (p *TagManagerPlugin) Description() string
func (*TagManagerPlugin) FormatTagMessage ¶ added in v0.7.0
func (p *TagManagerPlugin) FormatTagMessage(version semver.SemVersion) string
FormatTagMessage formats a tag message using the configured template.
func (*TagManagerPlugin) FormatTagName ¶
func (p *TagManagerPlugin) FormatTagName(version semver.SemVersion) string
FormatTagName formats a version as a tag name using the configured prefix.
func (*TagManagerPlugin) GetConfig ¶
func (p *TagManagerPlugin) GetConfig() *Config
GetConfig returns the plugin configuration.
func (*TagManagerPlugin) GetLatestTag ¶
func (p *TagManagerPlugin) GetLatestTag() (semver.SemVersion, error)
GetLatestTag returns the latest semver tag from git.
func (*TagManagerPlugin) IsAutoCreateEnabled ¶ added in v0.11.2
func (p *TagManagerPlugin) IsAutoCreateEnabled() bool
IsAutoCreateEnabled returns whether the plugin is enabled with auto-create on. This gates automatic tag validation and creation during bumps.
func (*TagManagerPlugin) Name ¶
func (p *TagManagerPlugin) Name() string
func (*TagManagerPlugin) SetPrefix ¶ added in v0.13.0
func (p *TagManagerPlugin) SetPrefix(prefix string)
SetPrefix temporarily overrides the tag prefix for per-module configuration.
func (*TagManagerPlugin) ShouldCreateTag ¶ added in v0.7.0
func (p *TagManagerPlugin) ShouldCreateTag(version semver.SemVersion) bool
ShouldCreateTag determines if a tag should be created for the given version. Returns true if tagging is enabled and either: - The version is a stable release (no pre-release), or - The version is a pre-release and TagPrereleases is true.
func (*TagManagerPlugin) TagExists ¶
func (p *TagManagerPlugin) TagExists(version semver.SemVersion) (bool, error)
TagExists checks if a tag for the given version already exists.
func (*TagManagerPlugin) ValidateTagAvailable ¶
func (p *TagManagerPlugin) ValidateTagAvailable(version semver.SemVersion) error
ValidateTagAvailable ensures a tag can be created for the version.
func (*TagManagerPlugin) Version ¶
func (p *TagManagerPlugin) Version() string
type TemplateData ¶ added in v0.7.0
type TemplateData struct {
Version string
Tag string
Prefix string
ModulePath string
Date string
Major string
Minor string
Patch string
PreRelease string
Build string
}
TemplateData holds values for template placeholder substitution.
func NewTemplateData ¶ added in v0.7.0
func NewTemplateData(version semver.SemVersion, prefix, modulePath string, opts ...NowFunc) TemplateData
NewTemplateData creates TemplateData from a version and prefix. An optional NowFunc can be provided to override time.Now (for testing).