Skip to content

Commit 4dfae9a

Browse files
authored
fix: deduplicate bulk commits (#2758)
Deduplicate nested commits with the same subject and library ID. Fixes #2690
1 parent bdc662c commit 4dfae9a

File tree

2 files changed

+33
-4
lines changed

2 files changed

+33
-4
lines changed

internal/gitrepo/conventional_commits.go

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -139,16 +139,21 @@ func ParseCommits(commit *Commit, libraryID string) ([]*ConventionalCommit, erro
139139
message = extractBeginCommitMessage(message)
140140

141141
var commits []*ConventionalCommit
142-
142+
seen := make(map[string]bool)
143143
for _, part := range extractCommitParts(message) {
144-
c, err := parseSimpleCommit(part, commit, libraryID)
144+
simpleCommits, err := parseSimpleCommit(part, commit, libraryID)
145145
if err != nil {
146146
slog.Warn("failed to parse commit part", "commit", part.message, "error", err)
147147
continue
148148
}
149149

150-
if c != nil {
151-
commits = append(commits, c...)
150+
for _, simpleCommit := range simpleCommits {
151+
key := fmt.Sprintf("%s,%s", simpleCommit.Subject, simpleCommit.LibraryID)
152+
if _, ok := seen[key]; ok {
153+
continue
154+
}
155+
seen[key] = true
156+
commits = append(commits, simpleCommit)
152157
}
153158
}
154159

internal/gitrepo/conventional_commits_test.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -601,6 +601,30 @@ END_COMMIT`,
601601
},
602602
},
603603
},
604+
{
605+
name: "nested_commits_with_identical_message",
606+
message: `
607+
BEGIN_NESTED_COMMIT
608+
fix(abc): update google.golang.org/api to 0.229.0
609+
END_NESTED_COMMIT
610+
BEGIN_NESTED_COMMIT
611+
fix(def): update google.golang.org/api to 0.229.0
612+
END_NESTED_COMMIT
613+
BEGIN_NESTED_COMMIT
614+
fix(cba): update google.golang.org/api to 0.229.0
615+
END_NESTED_COMMIT`,
616+
want: []*ConventionalCommit{
617+
{
618+
Type: "fix",
619+
Subject: "update google.golang.org/api to 0.229.0",
620+
LibraryID: "example-id",
621+
IsNested: true,
622+
Footers: map[string]string{},
623+
CommitHash: sha.String(),
624+
When: now,
625+
},
626+
},
627+
},
604628
} {
605629
t.Run(test.name, func(t *testing.T) {
606630
commit := &Commit{

0 commit comments

Comments
 (0)