mirror of
https://github.com/git-chglog/git-chglog.git
synced 2026-01-23 02:15:12 +00:00
feat: add option to filter commits in a case insensitive way
This commit is contained in:
parent
a94e3f9a80
commit
72fb3eac14
9 changed files with 88 additions and 26 deletions
|
|
@ -163,6 +163,7 @@ OPTIONS:
|
|||
--silent disable stdout output
|
||||
--no-color disable color output [$NO_COLOR]
|
||||
--no-emoji disable emoji output [$NO_EMOJI]
|
||||
--no-case disable case sensitive filters
|
||||
--tag-filter-pattern value, -p value regular expression of tag filter. Is specified, only matched tags will be picked
|
||||
--help, -h show help
|
||||
--version, -v print the version
|
||||
|
|
@ -548,4 +549,4 @@ See [CHANGELOG.md](./CHANGELOG.md)
|
|||
[doc-commit]: https://godoc.org/github.com/git-chglog/git-chglog#Commit
|
||||
[doc-commit-group]: https://godoc.org/github.com/git-chglog/git-chglog#Commit
|
||||
[doc-ref]: https://godoc.org/github.com/git-chglog/git-chglog#Ref
|
||||
[doc-render-data]: https://godoc.org/github.com/git-chglog/git-chglog#RenderData
|
||||
[doc-render-data]: https://godoc.org/github.com/git-chglog/git-chglog#RenderData
|
||||
|
|
|
|||
|
|
@ -19,6 +19,7 @@ type Options struct {
|
|||
Processor Processor
|
||||
NextTag string // Treat unreleased commits as specified tags (EXPERIMENTAL)
|
||||
TagFilterPattern string // Filter tag by regexp
|
||||
NoCaseSensitive bool // Filter commits in a case insensitive way
|
||||
CommitFilters map[string][]string // Filter by using `Commit` properties and values. Filtering is not done by specifying an empty value
|
||||
CommitSortBy string // Property name to use for sorting `Commit` (e.g. `Scope`)
|
||||
CommitGroupBy string // Property name of `Commit` to be grouped into `CommitGroup` (e.g. `Type`)
|
||||
|
|
|
|||
|
|
@ -259,6 +259,7 @@ func (config *Config) Convert(ctx *CLIContext) *chglog.Config {
|
|||
Options: &chglog.Options{
|
||||
NextTag: ctx.NextTag,
|
||||
TagFilterPattern: ctx.TagFilterPattern,
|
||||
NoCaseSensitive: ctx.NoCaseSensitive,
|
||||
CommitFilters: opts.Commits.Filters,
|
||||
CommitSortBy: opts.Commits.SortBy,
|
||||
CommitGroupBy: opts.CommitGroups.GroupBy,
|
||||
|
|
|
|||
|
|
@ -14,6 +14,7 @@ type CLIContext struct {
|
|||
Silent bool
|
||||
NoColor bool
|
||||
NoEmoji bool
|
||||
NoCaseSensitive bool
|
||||
Query string
|
||||
NextTag string
|
||||
TagFilterPattern string
|
||||
|
|
|
|||
|
|
@ -114,10 +114,16 @@ func CreateApp(actionFunc cli.ActionFunc) *cli.App {
|
|||
EnvVar: "NO_EMOJI",
|
||||
},
|
||||
|
||||
// no-case
|
||||
cli.BoolFlag{
|
||||
Name: "no-case",
|
||||
Usage: "disable case sensitive filters",
|
||||
},
|
||||
|
||||
// tag-filter-pattern
|
||||
cli.StringFlag{
|
||||
Name: "tag-filter-pattern, p",
|
||||
Usage: "Regular expression of tag filter. Is specified, only matched tags will be picked",
|
||||
Name: "tag-filter-pattern, p",
|
||||
Usage: "Regular expression of tag filter. Is specified, only matched tags will be picked",
|
||||
},
|
||||
|
||||
// help & version
|
||||
|
|
@ -162,16 +168,17 @@ func AppAction(c *cli.Context) error {
|
|||
// chglog
|
||||
chglogCLI := NewCLI(
|
||||
&CLIContext{
|
||||
WorkingDir: wd,
|
||||
Stdout: colorable.NewColorableStdout(),
|
||||
Stderr: colorable.NewColorableStderr(),
|
||||
ConfigPath: c.String("config"),
|
||||
OutputPath: c.String("output"),
|
||||
Silent: c.Bool("silent"),
|
||||
NoColor: c.Bool("no-color"),
|
||||
NoEmoji: c.Bool("no-emoji"),
|
||||
Query: c.Args().First(),
|
||||
NextTag: c.String("next-tag"),
|
||||
WorkingDir: wd,
|
||||
Stdout: colorable.NewColorableStdout(),
|
||||
Stderr: colorable.NewColorableStderr(),
|
||||
ConfigPath: c.String("config"),
|
||||
OutputPath: c.String("output"),
|
||||
Silent: c.Bool("silent"),
|
||||
NoColor: c.Bool("no-color"),
|
||||
NoEmoji: c.Bool("no-emoji"),
|
||||
NoCaseSensitive: c.Bool("no-case"),
|
||||
Query: c.Args().First(),
|
||||
NextTag: c.String("next-tag"),
|
||||
TagFilterPattern: c.String("tag-filter-pattern"),
|
||||
},
|
||||
fs,
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@ func TestCreateApp(t *testing.T) {
|
|||
gAssert = assert
|
||||
|
||||
app := CreateApp(mock_app_action)
|
||||
args := []string {
|
||||
args := []string{
|
||||
"git-chglog",
|
||||
"--silent",
|
||||
"--no-color",
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ func (e *commitExtractor) Extract(commits []*Commit) ([]*CommitGroup, []*Commit,
|
|||
mergeCommits := []*Commit{}
|
||||
revertCommits := []*Commit{}
|
||||
|
||||
filteredCommits := commitFilter(commits, e.opts.CommitFilters)
|
||||
filteredCommits := commitFilter(commits, e.opts.CommitFilters, e.opts.NoCaseSensitive)
|
||||
|
||||
for _, commit := range commits {
|
||||
if commit.Merge != nil {
|
||||
|
|
@ -37,7 +37,7 @@ func (e *commitExtractor) Extract(commits []*Commit) ([]*CommitGroup, []*Commit,
|
|||
|
||||
for _, commit := range filteredCommits {
|
||||
if commit.Merge == nil && commit.Revert == nil {
|
||||
e.processCommitGroups(&commitGroups, commit)
|
||||
e.processCommitGroups(&commitGroups, commit, e.opts.NoCaseSensitive)
|
||||
}
|
||||
|
||||
e.processNoteGroups(¬eGroups, commit)
|
||||
|
|
@ -49,14 +49,23 @@ func (e *commitExtractor) Extract(commits []*Commit) ([]*CommitGroup, []*Commit,
|
|||
return commitGroups, mergeCommits, revertCommits, noteGroups
|
||||
}
|
||||
|
||||
func (e *commitExtractor) processCommitGroups(groups *[]*CommitGroup, commit *Commit) {
|
||||
func (e *commitExtractor) processCommitGroups(groups *[]*CommitGroup, commit *Commit, noCaseSensitive bool) {
|
||||
var group *CommitGroup
|
||||
|
||||
// commit group
|
||||
raw, ttl := e.commitGroupTitle(commit)
|
||||
|
||||
for _, g := range *groups {
|
||||
if g.RawTitle == raw {
|
||||
rawTitleTmp := g.RawTitle
|
||||
if noCaseSensitive {
|
||||
rawTitleTmp = strings.ToLower(g.RawTitle)
|
||||
}
|
||||
|
||||
rawTmp := raw
|
||||
if noCaseSensitive {
|
||||
rawTmp = strings.ToLower(raw)
|
||||
}
|
||||
if rawTitleTmp == rawTmp {
|
||||
group = g
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,10 @@
|
|||
package chglog
|
||||
|
||||
func commitFilter(commits []*Commit, filters map[string][]string) []*Commit {
|
||||
import (
|
||||
"strings"
|
||||
)
|
||||
|
||||
func commitFilter(commits []*Commit, filters map[string][]string, noCaseSensitive bool) []*Commit {
|
||||
res := []*Commit{}
|
||||
|
||||
for _, commit := range commits {
|
||||
|
|
@ -23,9 +27,17 @@ func commitFilter(commits []*Commit, filters map[string][]string) []*Commit {
|
|||
break
|
||||
}
|
||||
|
||||
if noCaseSensitive {
|
||||
str = strings.ToLower(str)
|
||||
}
|
||||
|
||||
exist := false
|
||||
|
||||
for _, val := range values {
|
||||
if noCaseSensitive {
|
||||
val = strings.ToLower(val)
|
||||
}
|
||||
|
||||
if str == val {
|
||||
exist = true
|
||||
}
|
||||
|
|
|
|||
|
|
@ -38,6 +38,11 @@ func TestCommitFilter(t *testing.T) {
|
|||
Scope: "fuga",
|
||||
Subject: "4",
|
||||
},
|
||||
&Commit{
|
||||
Type: "Bar",
|
||||
Scope: "hogera",
|
||||
Subject: "5",
|
||||
},
|
||||
}
|
||||
|
||||
assert.Equal(
|
||||
|
|
@ -46,8 +51,9 @@ func TestCommitFilter(t *testing.T) {
|
|||
"2",
|
||||
"3",
|
||||
"4",
|
||||
"5",
|
||||
},
|
||||
pickCommitSubjects(commitFilter(fixtures, map[string][]string{})),
|
||||
pickCommitSubjects(commitFilter(fixtures, map[string][]string{}, false)),
|
||||
)
|
||||
|
||||
assert.Equal(
|
||||
|
|
@ -59,7 +65,20 @@ func TestCommitFilter(t *testing.T) {
|
|||
},
|
||||
pickCommitSubjects(commitFilter(fixtures, map[string][]string{
|
||||
"Type": {"foo", "bar"},
|
||||
})),
|
||||
}, false)),
|
||||
)
|
||||
|
||||
assert.Equal(
|
||||
[]string{
|
||||
"1",
|
||||
"2",
|
||||
"3",
|
||||
"4",
|
||||
"5",
|
||||
},
|
||||
pickCommitSubjects(commitFilter(fixtures, map[string][]string{
|
||||
"Type": {"foo", "bar"},
|
||||
}, true)),
|
||||
)
|
||||
|
||||
assert.Equal(
|
||||
|
|
@ -69,7 +88,7 @@ func TestCommitFilter(t *testing.T) {
|
|||
},
|
||||
pickCommitSubjects(commitFilter(fixtures, map[string][]string{
|
||||
"Type": {"foo"},
|
||||
})),
|
||||
}, false)),
|
||||
)
|
||||
|
||||
assert.Equal(
|
||||
|
|
@ -79,7 +98,18 @@ func TestCommitFilter(t *testing.T) {
|
|||
},
|
||||
pickCommitSubjects(commitFilter(fixtures, map[string][]string{
|
||||
"Type": {"bar"},
|
||||
})),
|
||||
}, false)),
|
||||
)
|
||||
|
||||
assert.Equal(
|
||||
[]string{
|
||||
"3",
|
||||
"4",
|
||||
"5",
|
||||
},
|
||||
pickCommitSubjects(commitFilter(fixtures, map[string][]string{
|
||||
"Type": {"bar"},
|
||||
}, true)),
|
||||
)
|
||||
|
||||
assert.Equal(
|
||||
|
|
@ -89,7 +119,7 @@ func TestCommitFilter(t *testing.T) {
|
|||
},
|
||||
pickCommitSubjects(commitFilter(fixtures, map[string][]string{
|
||||
"Scope": {"fuga"},
|
||||
})),
|
||||
}, false)),
|
||||
)
|
||||
|
||||
assert.Equal(
|
||||
|
|
@ -99,7 +129,7 @@ func TestCommitFilter(t *testing.T) {
|
|||
pickCommitSubjects(commitFilter(fixtures, map[string][]string{
|
||||
"Type": {"bar"},
|
||||
"Scope": {"hoge"},
|
||||
})),
|
||||
}, false)),
|
||||
)
|
||||
|
||||
assert.Equal(
|
||||
|
|
@ -110,6 +140,6 @@ func TestCommitFilter(t *testing.T) {
|
|||
pickCommitSubjects(commitFilter(fixtures, map[string][]string{
|
||||
"Type": {"foo"},
|
||||
"Scope": {"fuga", "hoge"},
|
||||
})),
|
||||
}, false)),
|
||||
)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue