feat: support grouping by date

This commit is contained in:
aeneasr 2023-02-10 12:01:28 +01:00
parent b0f4afeff4
commit 661fa688e0
No known key found for this signature in database
GPG key ID: 1A463E422E5E2222

View file

@ -3,6 +3,7 @@ package chglog
import (
"sort"
"strings"
"time"
)
type commitExtractor struct {
@ -114,14 +115,26 @@ func (e *commitExtractor) commitGroupTitle(commit *Commit) (string, string) {
)
if title, ok := dotGet(commit, e.opts.CommitGroupBy); ok {
if v, ok := title.(string); ok {
raw = v
if t, ok := e.opts.CommitGroupTitleMaps[v]; ok {
ttl = t
} else {
//nolint:staticcheck
ttl = strings.Title(raw)
}
switch titleType := title.(type) {
case string:
raw = titleType
case time.Time:
raw = titleType.Format("2006-01-02")
case *time.Time:
raw = titleType.Format("2006-01-02")
case interface {
String() string
}:
raw = titleType.String()
default:
return "", ""
}
if t, ok := e.opts.CommitGroupTitleMaps[raw]; ok {
ttl = t
} else {
//nolint:staticcheck
ttl = strings.Title(raw)
}
}