0
0
mirror of https://github.com/thegeeklab/git-sv.git synced 2024-11-21 22:10:39 +00:00

feat: migrate 'release-notes.headers' to 'release-notes.sections'

issue: #40
This commit is contained in:
Beatriz Vieira 2022-02-28 20:47:45 -03:00
parent ebb70048ee
commit 67042ac1e7
3 changed files with 11 additions and 9 deletions

View File

@ -70,7 +70,7 @@ func readConfig(filepath string) (Config, error) {
func defaultConfig() Config { func defaultConfig() Config {
skipDetached := false skipDetached := false
return Config{ return Config{
Version: "1.0", Version: "1.1",
Versioning: sv.VersioningConfig{ Versioning: sv.VersioningConfig{
UpdateMajor: []string{}, UpdateMajor: []string{},
UpdateMinor: []string{"feat"}, UpdateMinor: []string{"feat"},
@ -136,11 +136,11 @@ func (t *mergeTransformer) Transformer(typ reflect.Type) func(dst, src reflect.V
return nil return nil
} }
func migrateConfig(cfg Config) Config { func migrateConfig(cfg Config, filename string) Config {
if cfg.ReleaseNotes.Headers == nil { if cfg.ReleaseNotes.Headers == nil {
return cfg 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{ return Config{
Version: cfg.Version, Version: cfg.Version,

View File

@ -171,15 +171,17 @@ func loadCfg(repoPath string) Config {
envCfg := loadEnvConfig() envCfg := loadEnvConfig()
if envCfg.Home != "" { if envCfg.Home != "" {
if homeCfg, err := readConfig(filepath.Join(envCfg.Home, configFilename)); err == nil { homeCfgFilepath := filepath.Join(envCfg.Home, configFilename)
if merr := merge(&cfg, homeCfg); merr != nil { 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) log.Fatal("failed to merge user config, error: ", merr)
} }
} }
} }
if repoCfg, err := readConfig(filepath.Join(repoPath, repoConfigFilename)); err == nil { repoCfgFilepath := filepath.Join(repoPath, repoConfigFilename)
if merr := merge(&cfg, repoCfg); merr != nil { 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) log.Fatal("failed to merge repo config, error: ", merr)
} }
if len(repoCfg.ReleaseNotes.Headers) > 0 { // mergo is merging maps, headers will be overwritten if len(repoCfg.ReleaseNotes.Headers) > 0 { // mergo is merging maps, headers will be overwritten

View File

@ -68,7 +68,7 @@ type TagConfig struct {
// ReleaseNotesConfig release notes preferences. // ReleaseNotesConfig release notes preferences.
type ReleaseNotesConfig struct { type ReleaseNotesConfig struct {
Headers map[string]string `yaml:"headers"` Headers map[string]string `yaml:"headers,omitempty"`
Sections []ReleaseNotesSectionConfig `yaml:"sections"` Sections []ReleaseNotesSectionConfig `yaml:"sections"`
} }
@ -85,7 +85,7 @@ func (cfg ReleaseNotesConfig) sectionConfig(sectionType string) *ReleaseNotesSec
type ReleaseNotesSectionConfig struct { type ReleaseNotesSectionConfig struct {
Name string `yaml:"name"` Name string `yaml:"name"`
SectionType string `yaml:"section-type"` SectionType string `yaml:"section-type"`
CommitTypes []string `yaml:"commit-types"` CommitTypes []string `yaml:"commit-types,flow,omitempty"`
} }
const ( const (