From 67042ac1e70dc8b3ec5080582da5770df6d087e1 Mon Sep 17 00:00:00 2001 From: Beatriz Vieira Date: Mon, 28 Feb 2022 20:47:45 -0300 Subject: [PATCH] feat: migrate 'release-notes.headers' to 'release-notes.sections' issue: #40 --- cmd/git-sv/config.go | 6 +++--- cmd/git-sv/main.go | 10 ++++++---- sv/config.go | 4 ++-- 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/cmd/git-sv/config.go b/cmd/git-sv/config.go index 7e84068..4bbd0e2 100644 --- a/cmd/git-sv/config.go +++ b/cmd/git-sv/config.go @@ -70,7 +70,7 @@ func readConfig(filepath string) (Config, error) { func defaultConfig() Config { skipDetached := false return Config{ - Version: "1.0", + Version: "1.1", Versioning: sv.VersioningConfig{ UpdateMajor: []string{}, UpdateMinor: []string{"feat"}, @@ -136,11 +136,11 @@ func (t *mergeTransformer) Transformer(typ reflect.Type) func(dst, src reflect.V return nil } -func migrateConfig(cfg Config) Config { +func migrateConfig(cfg Config, filename string) Config { if cfg.ReleaseNotes.Headers == nil { return cfg } - warnf("config 'release-notes.headers' is deprecated, please use 'sections' instead!") + warnf("config 'release-notes.headers' on %s is deprecated, please use 'sections' instead!", filename) return Config{ Version: cfg.Version, diff --git a/cmd/git-sv/main.go b/cmd/git-sv/main.go index 6ecc1bf..b2a4a02 100644 --- a/cmd/git-sv/main.go +++ b/cmd/git-sv/main.go @@ -171,15 +171,17 @@ func loadCfg(repoPath string) Config { envCfg := loadEnvConfig() if envCfg.Home != "" { - if homeCfg, err := readConfig(filepath.Join(envCfg.Home, configFilename)); err == nil { - if merr := merge(&cfg, homeCfg); merr != nil { + homeCfgFilepath := filepath.Join(envCfg.Home, configFilename) + if homeCfg, err := readConfig(homeCfgFilepath); err == nil { + if merr := merge(&cfg, migrateConfig(homeCfg, homeCfgFilepath)); merr != nil { log.Fatal("failed to merge user config, error: ", merr) } } } - if repoCfg, err := readConfig(filepath.Join(repoPath, repoConfigFilename)); err == nil { - if merr := merge(&cfg, repoCfg); merr != nil { + repoCfgFilepath := filepath.Join(repoPath, repoConfigFilename) + if repoCfg, err := readConfig(repoCfgFilepath); err == nil { + if merr := merge(&cfg, migrateConfig(repoCfg, repoCfgFilepath)); merr != nil { log.Fatal("failed to merge repo config, error: ", merr) } if len(repoCfg.ReleaseNotes.Headers) > 0 { // mergo is merging maps, headers will be overwritten diff --git a/sv/config.go b/sv/config.go index 65d1679..af19378 100644 --- a/sv/config.go +++ b/sv/config.go @@ -68,7 +68,7 @@ type TagConfig struct { // ReleaseNotesConfig release notes preferences. type ReleaseNotesConfig struct { - Headers map[string]string `yaml:"headers"` + Headers map[string]string `yaml:"headers,omitempty"` Sections []ReleaseNotesSectionConfig `yaml:"sections"` } @@ -85,7 +85,7 @@ func (cfg ReleaseNotesConfig) sectionConfig(sectionType string) *ReleaseNotesSec type ReleaseNotesSectionConfig struct { Name string `yaml:"name"` SectionType string `yaml:"section-type"` - CommitTypes []string `yaml:"commit-types"` + CommitTypes []string `yaml:"commit-types,flow,omitempty"` } const (