0
0
mirror of https://github.com/thegeeklab/git-sv.git synced 2024-11-21 12:00:40 +00:00

fix: also support .yaml config (#124)

This commit is contained in:
Robert Kaussow 2024-10-20 12:48:54 +02:00 committed by GitHub
parent 4732ce1106
commit b605085837
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 23 additions and 30 deletions

View File

@ -1,6 +1,4 @@
--- ---
version: "1.1"
versioning: versioning:
update-major: [] update-major: []
update-minor: [feat] update-minor: [feat]

View File

@ -33,7 +33,7 @@ make build
The configuration is loaded from a YAML file in the following order (last wins): The configuration is loaded from a YAML file in the following order (last wins):
- built-in default - 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: To check the default configuration, run:
@ -42,8 +42,6 @@ git sv cfg default
``` ```
```Yaml ```Yaml
version: "1.1" # Configuration version.
versioning: versioning:
update-major: [] # Commit types used to bump major. update-major: [] # Commit types used to bump major.
update-minor: [feat] # Commit types used to bump minor. update-minor: [feat] # Commit types used to bump minor.

View File

@ -20,9 +20,6 @@ import (
const ( const (
logSeparator = "###" logSeparator = "###"
endLine = "~~~" endLine = "~~~"
configFilename = "config.yml"
configDir = ".gitsv"
) )
var errUnknownGitError = errors.New("git command failed") var errUnknownGitError = errors.New("git command failed")
@ -68,9 +65,12 @@ type GitSV struct {
// New constructor. // New constructor.
func New() GitSV { func New() GitSV {
configDir := ".gitsv"
configFilenames := []string{"config.yaml", "config.yml"}
g := GitSV{ g := GitSV{
Settings: &Settings{}, Settings: &Settings{},
Config: NewConfig(configDir, configFilename), Config: NewConfig(configDir, configFilenames),
} }
g.MessageProcessor = sv.NewMessageProcessor(g.Config.CommitMessage, g.Config.Branches) g.MessageProcessor = sv.NewMessageProcessor(g.Config.CommitMessage, g.Config.Branches)

View File

@ -56,7 +56,6 @@ type TagSettings struct {
// Config cli yaml config. // Config cli yaml config.
type Config struct { type Config struct {
Version string `yaml:"version"`
LogLevel string `yaml:"log-level"` LogLevel string `yaml:"log-level"`
Versioning sv.VersioningConfig `yaml:"versioning"` Versioning sv.VersioningConfig `yaml:"versioning"`
Tag TagConfig `yaml:"tag"` Tag TagConfig `yaml:"tag"`
@ -71,15 +70,19 @@ type TagConfig struct {
Filter *string `yaml:"filter"` Filter *string `yaml:"filter"`
} }
func NewConfig(configDir, configFilename string) *Config { func NewConfig(configDir string, configFilenames []string) *Config {
workDir, _ := os.Getwd() workDir, _ := os.Getwd()
cfg := GetDefault() cfg := GetDefault()
repoCfgFilepath := filepath.Join(workDir, configDir, configFilename) for _, filename := range configFilenames {
repoCfgFilepath := filepath.Join(workDir, configDir, filename)
if repoCfg, err := readFile(repoCfgFilepath); err == nil { if repoCfg, err := readFile(repoCfgFilepath); err == nil {
if merr := merge(cfg, migrate(repoCfg, repoCfgFilepath)); merr != nil { if merr := merge(cfg, repoCfg); merr != nil {
log.Fatal().Err(merr).Msg("failed to merge repo config") log.Fatal().Err(merr).Msg("failed to merge repo config")
} }
break
}
} }
return cfg return cfg
@ -107,7 +110,6 @@ func GetDefault() *Config {
filter := "" filter := ""
return &Config{ return &Config{
Version: "1.1",
Versioning: sv.VersioningConfig{ Versioning: sv.VersioningConfig{
UpdateMajor: []string{}, UpdateMajor: []string{},
UpdateMinor: []string{"feat"}, UpdateMinor: []string{"feat"},
@ -173,8 +175,3 @@ func (t *mergeTransformer) Transformer(typ reflect.Type) func(dst, src reflect.V
return nil return nil
} }
//nolint:revive
func migrate(cfg Config, filename string) Config {
return cfg
}

View File

@ -22,16 +22,16 @@ func Test_merge(t *testing.T) {
}{ }{
{ {
"overwrite string", "overwrite string",
Config{Version: "a"}, Config{LogLevel: "info"},
Config{Version: "b"}, Config{LogLevel: "warn"},
Config{Version: "b"}, Config{LogLevel: "warn"},
false, false,
}, },
{ {
"default string", "default string",
Config{Version: "a"}, Config{LogLevel: "info"},
Config{Version: ""}, Config{LogLevel: ""},
Config{Version: "a"}, Config{LogLevel: "info"},
false, false,
}, },
{ {
@ -120,21 +120,21 @@ func Test_merge(t *testing.T) {
{ {
"overwrite tag config", "overwrite tag config",
Config{ Config{
Version: "a", LogLevel: "info",
Tag: TagConfig{ Tag: TagConfig{
Pattern: &nonEmptyStr, Pattern: &nonEmptyStr,
Filter: &nonEmptyStr, Filter: &nonEmptyStr,
}, },
}, },
Config{ Config{
Version: "", LogLevel: "",
Tag: TagConfig{ Tag: TagConfig{
Pattern: &emptyStr, Pattern: &emptyStr,
Filter: &emptyStr, Filter: &emptyStr,
}, },
}, },
Config{ Config{
Version: "a", LogLevel: "info",
Tag: TagConfig{ Tag: TagConfig{
Pattern: &emptyStr, Pattern: &emptyStr,
Filter: &emptyStr, Filter: &emptyStr,