Improve calculation logic, add ability to strip prefixes.

This commit is contained in:
2025-12-10 14:37:38 +00:00
parent 18b9b474e0
commit 3a48a67c75
12 changed files with 376 additions and 127 deletions
+22 -12
View File
@@ -26,26 +26,36 @@ type Force struct {
// Config represents the application configuration
type Config struct {
Wording Wording
Force Force
Blacklist []string
Wording Wording
Force Force
Blacklist []string
TagPrefixes []string // Prefixes to strip from tags before parsing (e.g., "app-", "infra-", "v")
}
// ReadConfig reads the configuration from a file
func ReadConfig(file string) (*Config, error) {
config := &Config{}
viper.SetConfigFile(file)
err := viper.ReadInConfig()
if err != nil {
err = fmt.Errorf("fatal error config file: %s", err)
return config, err
}
viper.UnmarshalKey("wording", &config.Wording)
viper.UnmarshalKey("force", &config.Force)
viper.UnmarshalKey("blacklist", &config.Blacklist)
if err := viper.UnmarshalKey("wording", &config.Wording); err != nil {
return config, fmt.Errorf("error parsing wording config: %w", err)
}
if err := viper.UnmarshalKey("force", &config.Force); err != nil {
return config, fmt.Errorf("error parsing force config: %w", err)
}
if err := viper.UnmarshalKey("blacklist", &config.Blacklist); err != nil {
return config, fmt.Errorf("error parsing blacklist config: %w", err)
}
if err := viper.UnmarshalKey("tag_prefixes", &config.TagPrefixes); err != nil {
return config, fmt.Errorf("error parsing tag_prefixes config: %w", err)
}
return config, nil
}
@@ -55,14 +65,14 @@ func ApplyForcedVersioning(force Force, semver *SemVer) {
Debug("Forced versioning (MAJOR)", map[string]interface{}{"major": force.Major})
semver.Major = force.Major
}
if force.Minor > 0 {
Debug("Forced versioning (MINOR)", map[string]interface{}{"minor": force.Minor})
semver.Minor = force.Minor
}
if force.Patch > 0 {
Debug("Forced versioning (PATCH)", map[string]interface{}{"patch": force.Patch})
semver.Patch = force.Patch
}
}
}