Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions cmd/gohome/cmd/report.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,10 +201,7 @@ func processCommits(repos []string, author, period string, cfg *viperconfig.Conf
continue
}

commits := make([]entity.Commit, 0, len(rawLogs))
for _, line := range rawLogs {
commits = append(commits, parserSvc.Parse(line))
}
commits := parserSvc.Parse(rawLogs)

if len(commits) > 0 {
foundAny = true
Expand Down
19 changes: 18 additions & 1 deletion internal/parser/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func NewService() *Service {
}

// Parse converts a raw log line into a Commit entity.
func (s *Service) Parse(rawLine string) entity.Commit {
func (s *Service) parseSingleLine(rawLine string) entity.Commit {
emoji := s.extractEmoji(rawLine)
if emoji == "" {
emoji = "-"
Expand Down Expand Up @@ -49,6 +49,23 @@ func (s *Service) Parse(rawLine string) entity.Commit {
return commit
}

// Parse parses a slice of raw log lines and returns parsed commits with duplicate
// commit messages removed (keeps the first occurrence).
func (s *Service) Parse(rawLogs []string) []entity.Commit {
seen := make(map[string]bool)
result := make([]entity.Commit, 0, len(rawLogs))

for _, raw := range rawLogs {
if !seen[raw] {
seen[raw] = true
c := s.parseSingleLine(raw)
result = append(result, c)
}
}

return result
}

Comment thread
anIcedAntFA marked this conversation as resolved.
func (s *Service) extractEmoji(input string) string {
var emoji strings.Builder

Expand Down
6 changes: 3 additions & 3 deletions internal/parser/parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ func TestParse(t *testing.T) {
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
service := NewService()
got := service.Parse(tt.input)
got := service.parseSingleLine(tt.input)

if got.Type != tt.wantType {
t.Errorf("Parse(%q).Type = %q, want %q", tt.input, got.Type, tt.wantType)
Expand Down Expand Up @@ -454,7 +454,7 @@ func TestParseRawField(t *testing.T) {

for _, input := range testInputs {
t.Run(input, func(t *testing.T) {
got := service.Parse(input)
got := service.parseSingleLine(input)
if got.Raw != input {
t.Errorf("Parse(%q).Raw = %q, want %q", input, got.Raw, input)
}
Expand Down Expand Up @@ -501,7 +501,7 @@ func TestParseDefaultValues(t *testing.T) {
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
service := NewService()
got := service.Parse(tt.input)
got := service.parseSingleLine(tt.input)
tt.checkFunc(t, got)
})
}
Expand Down
Loading