0
0
mirror of https://github.com/thegeeklab/git-sv.git synced 2024-11-21 12:00:40 +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 {
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,

View File

@ -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

View File

@ -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 (