diff --git a/.gitsv/config.yml b/.gitsv/config.yml index acaf506..a1853bc 100644 --- a/.gitsv/config.yml +++ b/.gitsv/config.yml @@ -1,6 +1,4 @@ --- -version: "1.1" - versioning: update-major: [] update-minor: [feat] diff --git a/README.md b/README.md index 57e6a0e..27e6cf0 100644 --- a/README.md +++ b/README.md @@ -33,7 +33,7 @@ make build The configuration is loaded from a YAML file in the following order (last wins): - built-in default -- `.gitsv/config.yml` in repository root +- `.gitsv/config.yaml` or `.gitsv/config.yml` in repository root (first found) To check the default configuration, run: @@ -42,8 +42,6 @@ git sv cfg default ``` ```Yaml -version: "1.1" # Configuration version. - versioning: update-major: [] # Commit types used to bump major. update-minor: [feat] # Commit types used to bump minor. diff --git a/app/app.go b/app/app.go index b3aed38..c3fecf6 100644 --- a/app/app.go +++ b/app/app.go @@ -20,9 +20,6 @@ import ( const ( logSeparator = "###" endLine = "~~~" - - configFilename = "config.yml" - configDir = ".gitsv" ) var errUnknownGitError = errors.New("git command failed") @@ -68,9 +65,12 @@ type GitSV struct { // New constructor. func New() GitSV { + configDir := ".gitsv" + configFilenames := []string{"config.yaml", "config.yml"} + g := GitSV{ Settings: &Settings{}, - Config: NewConfig(configDir, configFilename), + Config: NewConfig(configDir, configFilenames), } g.MessageProcessor = sv.NewMessageProcessor(g.Config.CommitMessage, g.Config.Branches) diff --git a/app/config.go b/app/config.go index b819896..09b9106 100644 --- a/app/config.go +++ b/app/config.go @@ -56,7 +56,6 @@ type TagSettings struct { // Config cli yaml config. type Config struct { - Version string `yaml:"version"` LogLevel string `yaml:"log-level"` Versioning sv.VersioningConfig `yaml:"versioning"` Tag TagConfig `yaml:"tag"` @@ -71,14 +70,18 @@ type TagConfig struct { Filter *string `yaml:"filter"` } -func NewConfig(configDir, configFilename string) *Config { +func NewConfig(configDir string, configFilenames []string) *Config { workDir, _ := os.Getwd() cfg := GetDefault() - repoCfgFilepath := filepath.Join(workDir, configDir, configFilename) - if repoCfg, err := readFile(repoCfgFilepath); err == nil { - if merr := merge(cfg, migrate(repoCfg, repoCfgFilepath)); merr != nil { - log.Fatal().Err(merr).Msg("failed to merge repo config") + for _, filename := range configFilenames { + repoCfgFilepath := filepath.Join(workDir, configDir, filename) + if repoCfg, err := readFile(repoCfgFilepath); err == nil { + if merr := merge(cfg, repoCfg); merr != nil { + log.Fatal().Err(merr).Msg("failed to merge repo config") + } + + break } } @@ -107,7 +110,6 @@ func GetDefault() *Config { filter := "" return &Config{ - Version: "1.1", Versioning: sv.VersioningConfig{ UpdateMajor: []string{}, UpdateMinor: []string{"feat"}, @@ -173,8 +175,3 @@ func (t *mergeTransformer) Transformer(typ reflect.Type) func(dst, src reflect.V return nil } - -//nolint:revive -func migrate(cfg Config, filename string) Config { - return cfg -} diff --git a/app/config_test.go b/app/config_test.go index ffd8808..417888b 100644 --- a/app/config_test.go +++ b/app/config_test.go @@ -22,16 +22,16 @@ func Test_merge(t *testing.T) { }{ { "overwrite string", - Config{Version: "a"}, - Config{Version: "b"}, - Config{Version: "b"}, + Config{LogLevel: "info"}, + Config{LogLevel: "warn"}, + Config{LogLevel: "warn"}, false, }, { "default string", - Config{Version: "a"}, - Config{Version: ""}, - Config{Version: "a"}, + Config{LogLevel: "info"}, + Config{LogLevel: ""}, + Config{LogLevel: "info"}, false, }, { @@ -120,21 +120,21 @@ func Test_merge(t *testing.T) { { "overwrite tag config", Config{ - Version: "a", + LogLevel: "info", Tag: TagConfig{ Pattern: &nonEmptyStr, Filter: &nonEmptyStr, }, }, Config{ - Version: "", + LogLevel: "", Tag: TagConfig{ Pattern: &emptyStr, Filter: &emptyStr, }, }, Config{ - Version: "a", + LogLevel: "info", Tag: TagConfig{ Pattern: &emptyStr, Filter: &emptyStr,