github.com/Trim21/git-chglog@v0.0.0-20200414013904-db796966b373/commit_filter.go (about)

     1  package chglog
     2  
     3  import (
     4  	"strings"
     5  )
     6  
     7  func commitFilter(commits []*Commit, filters map[string][]string, noCaseSensitive bool) []*Commit {
     8  	res := []*Commit{}
     9  
    10  	for _, commit := range commits {
    11  		include := false
    12  
    13  		if len(filters) == 0 {
    14  			include = true
    15  		}
    16  
    17  		for key, values := range filters {
    18  			prop, ok := dotGet(commit, key)
    19  			if !ok {
    20  				include = false
    21  				break
    22  			}
    23  
    24  			str, ok := prop.(string)
    25  			if !ok {
    26  				include = false
    27  				break
    28  			}
    29  
    30  			if noCaseSensitive {
    31  				str = strings.ToLower(str)
    32  			}
    33  
    34  			exist := false
    35  
    36  			for _, val := range values {
    37  				if noCaseSensitive {
    38  					val = strings.ToLower(val)
    39  				}
    40  
    41  				if str == val {
    42  					exist = true
    43  				}
    44  			}
    45  
    46  			if !exist {
    47  				include = false
    48  				break
    49  			}
    50  
    51  			include = true
    52  		}
    53  
    54  		if include {
    55  			res = append(res, commit)
    56  		}
    57  	}
    58  
    59  	return res
    60  }