fix: also support .yaml config (#124)
This commit is contained in:
parent
4732ce1106
commit
b605085837
5 changed files with 23 additions and 30 deletions
|
@ -1,6 +1,4 @@
|
|||
---
|
||||
version: "1.1"
|
||||
|
||||
versioning:
|
||||
update-major: []
|
||||
update-minor: [feat]
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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,
|
||||
|
|
Loading…
Reference in a new issue