forked from git-chglog/git-chglog
-
Notifications
You must be signed in to change notification settings - Fork 0
/
commit_filter.go
64 lines (49 loc) · 1.02 KB
/
commit_filter.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package chglog
import (
"strings"
)
func commitFilter(commits []*Commit, filters map[string][]string, noCaseSensitive bool) []*Commit { //nolint:gocyclo
// NOTE(khos2ow): this function is over our cyclomatic complexity goal.
// Be wary when adding branches, and look for functionality that could
// be reasonably moved into an injected dependency.
res := []*Commit{}
for _, commit := range commits {
include := false
if len(filters) == 0 {
include = true
}
for key, values := range filters {
prop, ok := dotGet(commit, key)
if !ok {
include = false
break
}
str, ok := prop.(string)
if !ok {
include = false
break
}
if noCaseSensitive {
str = strings.ToLower(str)
}
exist := false
for _, val := range values {
if noCaseSensitive {
val = strings.ToLower(val)
}
if str == val {
exist = true
}
}
if !exist {
include = false
break
}
include = true
}
if include {
res = append(res, commit)
}
}
return res
}