feat: enable tag_filter_pattern in config options (#72)

Closes #70
This commit is contained in:
Trim21 2021-01-09 16:51:14 +08:00 committed by GitHub
parent 0ae5e13a06
commit 75d59a9eb8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 42 additions and 8 deletions

View file

@ -224,6 +224,8 @@ info:
repository_url: https://github.com/git-chglog/git-chglog
options:
tag_filter_pattern: '^v'
commits:
filters:
Type:

View file

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

View file

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