Documentation
¶
Overview ¶
Package commitmate: Advanced Git commit automation engine with intelligent Go formatting Features smart commit workflows with auto Go source code formatting and remote-based signature-info selection Provides seamless staging, formatting, committing, and amend operations with configuration-driven signatures Supports wildcard pattern matching for Git remote URLs to auto-select appropriate commit signatures
commitmate: 高级 Git 提交自动化引擎,带有智能 Go 格式化功能 具有智能提交工作流程,包含自动 Go 源代码格式化和基于远程的身份选择 提供无缝的暂存、格式化、提交和 amend 操作,支持配置驱动的签名 支持 Git 远程 URL 的通配符模式匹配,自动选择合适的提交签名
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DefaultAllowFormat ¶
DefaultAllowFormat is the default check function for Go files formatting Skips common generated files like .pb.go, wire_gen.go, and ent files Returns true if the file should be formatted, false to skip
DefaultAllowFormat 是 Go 文件格式化的默认过滤函数 跳过常见的生成文件,如 .pb.go、wire_gen.go 和 ent 文件 如果文件应该被格式化则返回 true,跳过则返回 false
func FormatChangedGoFiles ¶
func FormatChangedGoFiles(projectRoot string, client *gogit.Client, allowFormat func(path string) bool) error
FormatChangedGoFiles formats Go files that have been changed Uses allowFormat function to determine which files should be formatted Applies Go formatting to eligible files and logs the process
格式化已改变的 Go 文件 使用 allowFormat 函数确定哪些文件应该被格式化 对符合条件的文件应用 Go 格式化并记录过程
func GitCommit ¶
func GitCommit(projectRoot string, commitFlags *CommitFlags) error
GitCommit performs the complete commit workflow with selective Go code formatting Stages all changes, formats Go files when needed, and creates commits as requested Returns error if some step in the commit process fails
执行完整的提交工作流程,可选的 Go 代码格式化 暂存所有更改,可选格式化 Go 文件,并创建或 amend 提交 如果提交过程中的某个步骤失败则返回错误
Types ¶
type CommitConfig ¶ added in v0.0.3
type CommitConfig struct {
Signatures []*SignatureConfig `json:"signatures"` // List of configured signatures // 配置的签名列表
}
CommitConfig represents the comprehensive configuration system for go-commit Contains intelligent signature mappings for automated Git commit operations Enables automatic signature selection based on Git remote URL pattern matching Supports scoring-based matching with wildcard patterns for enterprise and custom workflows
CommitConfig 代表 go-commit 应用的全面配置系统 包含用于自动化 Git 提交操作的智能签名映射 基于 Git 远程 URL 模式匹配实现自动签名选择 支持基于评分的通配符模式匹配,适用于企业和自定义工作流程
func GenerateConfigTemplate ¶ added in v0.0.5
func GenerateConfigTemplate(projectRoot string) *CommitConfig
GenerateConfigTemplate generates a configuration template for the current project Analyzes current Git remote URL and creates a suggested configuration template Provides starter configuration with placeholders for username and email settings Outputs JSON template to stdout for easy copying and customization
GenerateConfigTemplate 为当前项目生成配置模板 分析当前 Git 远程 URL 并创建建议的配置模板 提供带有用户名和邮箱设置占位符的启动配置 将 JSON 模板输出到 stdout 以便复制和自定义
func LoadConfig ¶ added in v0.0.3
func LoadConfig(configPath string) *CommitConfig
LoadConfig loads the go-commit configuration from the specified file path Reads, validates, and parses the JSON configuration file with signature mappings Utilizes osmustexist for file validation and rese/must for robust error handling Returns complete loaded configuration suited for signature matching operations
LoadConfig 从指定文件路径加载 go-commit 配置 读取、验证并解析包含签名映射的 JSON 配置文件 使用 osmustexist 进行文件验证和 rese/must 进行强健的错误处理 返回完全加载的配置,准备进行签名匹配操作
func (*CommitConfig) MatchSignature ¶ added in v0.0.3
func (config *CommitConfig) MatchSignature(remoteURL string) *SignatureConfig
MatchSignature finds the best signature configuration for the specified remote URL Employs sophisticated pattern matching with wildcards and score-based ranking selection Evaluates all configured signature patterns and returns the highest-scoring match Returns the best matched signature or nil if no patterns match the remote URL
MatchSignature 为指定的远程 URL 找到最佳的签名配置 采用复杂的通配符模式匹配和基于评分的优先级选择 评估所有配置的签名模式并返回得分最高的匹配 返回最佳匹配的签名,如果没有模式匹配远程 URL 则返回 nil
func (*CommitConfig) ResolveSignature ¶ added in v0.0.5
func (config *CommitConfig) ResolveSignature(projectRoot string) (*SignatureConfig, error)
ResolveSignature resolves Git signature based on project repo remotes Extracts Git remote URLs and performs pattern-based signature matching Prioritizes 'origin' remote but falls back to first available remote for signature resolution Returns the best matched signature or nil if no suitable patterns match the remote configuration
ResolveSignature 基于项目仓库远程解析 Git 签名 提取 Git 远程 URL 并执行基于模式的签名匹配 优先使用 'origin' 远程,但在签名解析时回退到第一个可用远程 返回最佳匹配的签名,如果没有合适的模式匹配远程配置则返回 nil
type CommitFlags ¶
type CommitFlags struct { Username string // Git account username // Git 账户用户名 Message string // Commit message content // 提交消息内容 IsAmend bool // Enable amend mode on previous commit // 启用对上一次提交的 amend 模式 IsForce bool // Force amend even if pushed to remote // 即使推送到远程也强制 amend Mailbox string // Git account mailbox address (preferred) // Git 账户邮箱地址(优先) Eddress string // Git account mailbox address (fallback) // Git 账户邮箱地址(备选) NoCommit bool // Stage changes without committing // 仅暂存更改而不提交 FormatGo bool // Format changed Go files before commit // 提交前格式化已改变的 Go 文件 AutoSign bool // Use Git config as fallback // 使用 Git 配置作为备选 }
CommitFlags represents the configuration for a commit operation Contains all custom options for customizing commit actions Supports amend mode, force operations, and selective Go formatting
CommitFlags 代表提交操作的配置 包含所有用户指定的自定义提交行为选项 支持 amend 模式、强制操作和选择性 Go 格式化
func (*CommitFlags) ApplyProjectConfig ¶ added in v0.0.5
func (f *CommitFlags) ApplyProjectConfig(projectRoot string, config *CommitConfig)
ApplyProjectConfig applies project-specific configuration to commit flags Resolves appropriate signature from config based on project remote URLs Auto-selects and applies the best matching signature configuration
ApplyProjectConfig 将项目特定配置应用到提交标志 基于项目远程 URL 从配置中解析合适的签名 自动选择并使用最佳匹配的签名配置
func (*CommitFlags) ApplySignature ¶ added in v0.0.5
func (f *CommitFlags) ApplySignature(signature *SignatureConfig)
ApplySignature applies signature configuration to flags Signature config values override existing flag values when signature fields are not empty
ApplySignature 将签名配置应用到标志 当签名字段非空时,签名配置值会覆盖现有标志值
func (*CommitFlags) ValidateFlags ¶ added in v0.0.8
func (f *CommitFlags) ValidateFlags() []string
ValidateFlags performs basic validation on commit flags and returns warnings Checks for logical conflicts and missing essential information Returns slice of warning messages for potential issues
ValidateFlags 对提交标志执行基本验证并返回警告 检查逻辑冲突和缺失的基本信息 返回潜在问题的警告消息切片
type SignatureConfig ¶ added in v0.0.3
type SignatureConfig struct { Name string `json:"name"` // Config name for reference // 配置名称用于引用 Username string `json:"username"` // Git username for commits // 用于提交的 Git 用户名 Mailbox string `json:"mailbox"` // Git mailbox for commits (preferred) // 用于提交的 Git 邮箱(优先) Eddress string `json:"eddress"` // Git mailbox for commits (fallback) // 用于提交的 Git 邮箱(备选) RemotePatterns []string `json:"remotePatterns"` // Remote URL patterns (supports wildcards) // 远程 URL 模式(支持通配符) }
SignatureConfig represents a Git signature configuration with advanced pattern matching Maps Git remote URL patterns to corresponding account username and mailbox settings Supports sophisticated wildcard matching for flexible remote pattern definitions Enables automatic signature-info switching based on repo remote configurations
SignatureConfig 代表具有高级模式匹配的 Git 签名配置 将 Git 远程 URL 模式映射到相应的账户用户名和邮箱设置 支持复杂的通配符匹配以实现灵活的远程模式定义 基于代码库远程配置实现自动身份切换