From 661fa688e0759db9f9c935591c7a59dafb8fceef Mon Sep 17 00:00:00 2001 From: aeneasr <3372410+aeneasr@users.noreply.github.com> Date: Fri, 10 Feb 2023 12:01:28 +0100 Subject: [PATCH] feat: support grouping by date --- commit_extractor.go | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/commit_extractor.go b/commit_extractor.go index 1c4fc2ad..765cb174 100644 --- a/commit_extractor.go +++ b/commit_extractor.go @@ -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) } }