diff --git a/README.md b/README.md index 94961589..0b98c4e5 100644 --- a/README.md +++ b/README.md @@ -224,6 +224,8 @@ info: repository_url: https://github.com/git-chglog/git-chglog options: + tag_filter_pattern: '^v' + commits: filters: Type: diff --git a/cmd/git-chglog/config.go b/cmd/git-chglog/config.go index 4f6cc89e..bd48b691 100644 --- a/cmd/git-chglog/config.go +++ b/cmd/git-chglog/config.go @@ -50,14 +50,15 @@ type NoteOptions struct { // Options ... type Options struct { - Commits CommitOptions `yaml:"commits"` - CommitGroups CommitGroupOptions `yaml:"commit_groups"` - Header PatternOptions `yaml:"header"` - Issues IssueOptions `yaml:"issues"` - Refs RefOptions `yaml:"refs"` - Merges PatternOptions `yaml:"merges"` - Reverts PatternOptions `yaml:"reverts"` - Notes NoteOptions `yaml:"notes"` + TagFilterPattern string `yaml:"tag_filter_pattern"` + Commits CommitOptions `yaml:"commits"` + CommitGroups CommitGroupOptions `yaml:"commit_groups"` + Header PatternOptions `yaml:"header"` + Issues IssueOptions `yaml:"issues"` + Refs RefOptions `yaml:"refs"` + Merges PatternOptions `yaml:"merges"` + Reverts PatternOptions `yaml:"reverts"` + Notes NoteOptions `yaml:"notes"` } // Config ... @@ -248,6 +249,10 @@ func (config *Config) Convert(ctx *CLIContext) *chglog.Config { info := config.Info opts := config.Options + if ctx.TagFilterPattern == "" { + ctx.TagFilterPattern = opts.TagFilterPattern + } + return &chglog.Config{ Bin: config.Bin, WorkingDir: ctx.WorkingDir, diff --git a/cmd/git-chglog/config_test.go b/cmd/git-chglog/config_test.go index a56372f5..99edbe5e 100644 --- a/cmd/git-chglog/config_test.go +++ b/cmd/git-chglog/config_test.go @@ -41,3 +41,30 @@ func TestConfigNormalize(t *testing.T) { assert.Nil(err) assert.Equal(filepath.Join(cwd, "CHANGELOG.tpl.md"), config.Template) } + +func TestConfigConvert(t *testing.T) { + var patternInFile = "pattern in config" + var patternInArgs = "pattern in cli" + assert := assert.New(t) + // basic + config := &Config{ + Info: Info{ + RepositoryURL: "https://example.com/foo/bar/", + }, + Options: Options{TagFilterPattern: patternInFile}, + } + cli := &CLIContext{TagFilterPattern: patternInArgs} + cfg := config.Convert(cli) + assert.Equal(cfg.Options.TagFilterPattern, patternInArgs) + + config = &Config{ + Info: Info{ + RepositoryURL: "https://example.com/foo/bar/", + }, + Options: Options{TagFilterPattern: patternInFile}, + } + cli = &CLIContext{} + cfg = config.Convert(cli) + assert.Equal(cfg.Options.TagFilterPattern, patternInFile) + +}