From 2f9c935fec12264698ced5aa6a549de7c00bae3a Mon Sep 17 00:00:00 2001 From: Saurabh Kumar Singh Date: Sat, 18 Apr 2026 22:20:01 +0530 Subject: [PATCH 1/2] feat: Scan merge commit side-parents to fix PR discovery Signed-off-by: Saurabh Kumar Singh --- pkg/notes/notes.go | 68 +++++++++++++++++++++++++++++++++++----------- 1 file changed, 52 insertions(+), 16 deletions(-) diff --git a/pkg/notes/notes.go b/pkg/notes/notes.go index 3e27e455ea6..b5128006fee 100644 --- a/pkg/notes/notes.go +++ b/pkg/notes/notes.go @@ -736,6 +736,10 @@ func (g *Gatherer) listLeftParentCommits(opts *options.Options) ([]*commitPrPair pairs := []*commitPrPair{} hashPointer := currentTagHash + // Track PRs we've already emitted because the same PR can be discoverable + // from multiple commits or merge parents. + seenPRs := map[int]struct{}{} + for hashPointer != stopHash { hashString := hashPointer.String() @@ -755,30 +759,62 @@ func (g *Gatherer) listLeftParentCommits(opts *options.Options) ([]*commitPrPair logrus.WithFields(logrus.Fields{ "sha": hashString, }).Debug("no associated PR found") - - hashPointer = commitPointer.ParentHashes[0] - - continue - } - - if err != nil { + } else if err != nil { logrus.WithFields(logrus.Fields{ "sha": hashString, }).Warnf("ignore err: %v", err) + } else { + logrus.WithFields(logrus.Fields{ + "sha": hashString, + "prs": prNums, + }).Debug("found PR from commit") - hashPointer = commitPointer.ParentHashes[0] - - continue + if _, ok := seenPRs[prNums[0]]; !ok { + pairs = append(pairs, &commitPrPair{Commit: commitPointer, PrNum: prNums[0]}) + seenPRs[prNums[0]] = struct{}{} + } } - logrus.WithFields(logrus.Fields{ - "sha": hashString, - "prs": prNums, - }).Debug("found PR from commit") + // For merge commits, inspect non-first parents as well. This catches PRs + // that might not be visible from first-parent traversal alone. + if len(commitPointer.ParentHashes) > 1 { + for _, parentHash := range commitPointer.ParentHashes[1:] { + parentCommit, err := localRepository.CommitObject(parentHash) + if err != nil { + logrus.WithFields(logrus.Fields{ + "sha": hashString, + "parent": parentHash.String(), + }).Warnf("ignore parent commit lookup err: %v", err) + continue + } + + parentPRNums, err := prsNumForCommitFromMessage(parentCommit.Message) + if errors.Is(err, errNoPRIDFoundInCommitMessage) { + continue + } - // Only taking the first one, assuming they are merged by Prow - pairs = append(pairs, &commitPrPair{Commit: commitPointer, PrNum: prNums[0]}) + if err != nil { + logrus.WithFields(logrus.Fields{ + "sha": hashString, + "parent": parentHash.String(), + }).Warnf("ignore parent PR parse err: %v", err) + continue + } + + logrus.WithFields(logrus.Fields{ + "sha": hashString, + "parent_sha": parentHash.String(), + "prs": parentPRNums, + }).Debug("found PR from non-first parent") + + if _, ok := seenPRs[parentPRNums[0]]; !ok { + pairs = append(pairs, &commitPrPair{Commit: parentCommit, PrNum: parentPRNums[0]}) + seenPRs[parentPRNums[0]] = struct{}{} + } + } + } + // Continue along the first parent to stay on the release branch lineage. hashPointer = commitPointer.ParentHashes[0] } From 35cabc62025dbd7892d3cbb7bf50ddf398d9f4e6 Mon Sep 17 00:00:00 2001 From: Saurabh Kumar Singh Date: Sat, 18 Apr 2026 23:26:13 +0530 Subject: [PATCH 2/2] chore: fix linting issues in notes file Signed-off-by: Saurabh Kumar Singh --- pkg/notes/notes.go | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/pkg/notes/notes.go b/pkg/notes/notes.go index b5128006fee..61a06fe714e 100644 --- a/pkg/notes/notes.go +++ b/pkg/notes/notes.go @@ -755,15 +755,16 @@ func (g *Gatherer) listLeftParentCommits(opts *options.Options) ([]*commitPrPair // Find and collect PR number from commit message prNums, err := prsNumForCommitFromMessage(commitPointer.Message) - if errors.Is(err, errNoPRIDFoundInCommitMessage) { + switch { + case errors.Is(err, errNoPRIDFoundInCommitMessage): logrus.WithFields(logrus.Fields{ "sha": hashString, }).Debug("no associated PR found") - } else if err != nil { + case err != nil: logrus.WithFields(logrus.Fields{ "sha": hashString, }).Warnf("ignore err: %v", err) - } else { + default: logrus.WithFields(logrus.Fields{ "sha": hashString, "prs": prNums, @@ -785,6 +786,7 @@ func (g *Gatherer) listLeftParentCommits(opts *options.Options) ([]*commitPrPair "sha": hashString, "parent": parentHash.String(), }).Warnf("ignore parent commit lookup err: %v", err) + continue } @@ -798,6 +800,7 @@ func (g *Gatherer) listLeftParentCommits(opts *options.Options) ([]*commitPrPair "sha": hashString, "parent": parentHash.String(), }).Warnf("ignore parent PR parse err: %v", err) + continue }