Skip to content

Commit cd923ee

Browse files
committed
🐛 fix(parser): handle deduplicate commit messsage
1 parent 1a19135 commit cd923ee

File tree

2 files changed

+19
-5
lines changed

2 files changed

+19
-5
lines changed

cmd/gohome/cmd/report.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -201,10 +201,7 @@ func processCommits(repos []string, author, period string, cfg *viperconfig.Conf
201201
continue
202202
}
203203

204-
commits := make([]entity.Commit, 0, len(rawLogs))
205-
for _, line := range rawLogs {
206-
commits = append(commits, parserSvc.Parse(line))
207-
}
204+
commits := parserSvc.Parse(rawLogs)
208205

209206
if len(commits) > 0 {
210207
foundAny = true

internal/parser/parser.go

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ func NewService() *Service {
2020
}
2121

2222
// Parse converts a raw log line into a Commit entity.
23-
func (s *Service) Parse(rawLine string) entity.Commit {
23+
func (s *Service) parseSingleLine(rawLine string) entity.Commit {
2424
emoji := s.extractEmoji(rawLine)
2525
if emoji == "" {
2626
emoji = "-"
@@ -49,6 +49,23 @@ func (s *Service) Parse(rawLine string) entity.Commit {
4949
return commit
5050
}
5151

52+
// Parse parses a slice of raw log lines and returns parsed commits with duplicate
53+
// commit messages removed (keeps the first occurrence).
54+
func (s *Service) Parse(rawLogs []string) []entity.Commit {
55+
seen := make(map[string]bool)
56+
result := make([]entity.Commit, 0, len(rawLogs))
57+
58+
for _, raw := range rawLogs {
59+
if !seen[raw] {
60+
seen[raw] = true
61+
c := s.parseSingleLine(raw)
62+
result = append(result, c)
63+
}
64+
}
65+
66+
return result
67+
}
68+
5269
func (s *Service) extractEmoji(input string) string {
5370
var emoji strings.Builder
5471

0 commit comments

Comments
 (0)