github.com/fredbi/git-chglog@v0.0.0-20190706071416-d35c598eac81/commit_filter.go (about) 1 package chglog 2 3 func commitFilter(commits []*Commit, filters map[string][]string) []*Commit { 4 res := []*Commit{} 5 expandedCommits := []*Commit{} 6 7 for _, commit := range commits { 8 // expand squashed entries 9 expandedCommits = append(expandedCommits, commit) 10 if len(commit.AllHeaders) > 0 { 11 expandedCommits = append(expandedCommits, commit.AllHeaders...) 12 } 13 } 14 15 for _, commit := range expandedCommits { 16 include := false 17 18 if len(filters) == 0 { 19 include = true 20 } 21 22 for key, values := range filters { 23 prop, ok := dotGet(commit, key) 24 if !ok { 25 include = false 26 break 27 } 28 29 str, ok := prop.(string) 30 if !ok { 31 include = false 32 break 33 } 34 35 exist := false 36 37 for _, val := range values { 38 if str == val { 39 exist = true 40 } 41 } 42 43 if !exist { 44 include = false 45 break 46 } 47 48 include = true 49 } 50 51 if include { 52 res = append(res, commit) 53 } 54 } 55 56 return res 57 }