From d7813a54e53982b0cf33913e02346547e9a54111 Mon Sep 17 00:00:00 2001 From: scanner <280983584+hivecommons-hive[bot]@users.noreply.github.com> Date: Wed, 28 Oct 2026 10:58:48 -0400 Subject: [PATCH 1/5] =?UTF-8?q?=F0=9F=90=9B=20fix(dashboard):=20only=20lin?= =?UTF-8?q?k=20cross-referenced=20PRs=20that=20actually=20fix=20the=20issu?= =?UTF-8?q?e?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: scanner <280983584+hivecommons-hive[bot]@users.noreply.github.com> --- ...ixed-14966-prlink-cross-reference-mentions.md | 1 + src/pkg/dashboard/contribute_prlink.go | 16 ++++++++++++++++ src/pkg/dashboard/contribute_prlink_test.go | 14 ++++++++++++++ 3 files changed, 31 insertions(+) create mode 100644 changelog.d/fixed-14966-prlink-cross-reference-mentions.md diff --git a/changelog.d/fixed-14966-prlink-cross-reference-mentions.md b/changelog.d/fixed-14966-prlink-cross-reference-mentions.md new file mode 100644 index 0000000000..837c4e08b9 --- /dev/null +++ b/changelog.d/fixed-14966-prlink-cross-reference-mentions.md @@ -0,0 +1 @@ +The dashboard no longer marks an issue as Reviewing just because an open pull request mentions it; a timeline cross-reference now counts as the linked PR only when that PR's title or body closes the issue (Closes/Fixes/Resolves). diff --git a/src/pkg/dashboard/contribute_prlink.go b/src/pkg/dashboard/contribute_prlink.go index a963f3715e..164e903c85 100644 --- a/src/pkg/dashboard/contribute_prlink.go +++ b/src/pkg/dashboard/contribute_prlink.go @@ -8,6 +8,7 @@ import ( "time" gh "github.com/google/go-github/v72/github" + "github.com/hivecommons/hive/pkg/github" ) const ( @@ -179,6 +180,9 @@ func searchLinkedPR(ctx context.Context, gc *gh.Client, repo string, number int) // arrive as referenced events and are not matched here. A // timeline error keeps whatever the search already found. for _, iss := range crossReferencingPRs(ctx, gc, repo, number) { + if !prClosesIssue(iss, repo, number) { + continue + } st, merged := prLinkCandidate(iss) if merged { return st, nil @@ -256,6 +260,18 @@ func crossReferencingPRs(ctx context.Context, gc *gh.Client, repo string, number // cheap and within a single request. const prLinkSearchPerPage = 10 +// prClosesIssue reports whether a timeline cross-referencing PR names the +// issue as a fix (Closes/Fixes/Resolves) in its title or body, so a PR that +// merely mentions the issue is not promoted as its linked PR. A source with +// no title or body (omitted by the API) is accepted, as in prReferencesIssue. +func prClosesIssue(iss *gh.Issue, repo string, number int) bool { + if iss.GetBody() == "" && iss.GetTitle() == "" { + return true + } + _, ok := github.FindClosingKeywordReference(iss.GetTitle()+"\n"+iss.GetBody(), repo, repo, number) + return ok +} + // prReferencesIssue guards against a coincidental number collision: the Search // "#N" match is broad, so confirm the PR actually names the issue as a reference // (Fixes/Closes/Resolves #N, or a bare #N mention) in its title or body before diff --git a/src/pkg/dashboard/contribute_prlink_test.go b/src/pkg/dashboard/contribute_prlink_test.go index ee43519366..4b8add7ec5 100644 --- a/src/pkg/dashboard/contribute_prlink_test.go +++ b/src/pkg/dashboard/contribute_prlink_test.go @@ -396,6 +396,8 @@ func TestSearchLinkedPR_CountsCommitCommentAndTimelineReferences(t *testing.T) { openPR := `{"number":14656,"state":"open","html_url":"https://github.com/o/r/pull/14656","repository":{"full_name":"o/r"},"pull_request":{"url":"x"}}` mergedPR := `{"number":14656,"state":"closed","html_url":"https://github.com/o/r/pull/14656","repository":{"full_name":"o/r"},"pull_request":{"url":"x","merged_at":"2026-10-28T00:00:00Z"}}` otherRepoPR := `{"number":77,"state":"open","html_url":"https://github.com/x/y/pull/77","repository":{"full_name":"x/y"},"pull_request":{"url":"x"}}` + mentionPR := `{"number":14700,"state":"open","title":"unrelated work","body":"see also #13135 for context","html_url":"https://github.com/o/r/pull/14700","repository":{"full_name":"o/r"},"pull_request":{"url":"x"}}` + closingPR := `{"number":14701,"state":"open","title":"fix it","body":"Closes #13135","html_url":"https://github.com/o/r/pull/14701","repository":{"full_name":"o/r"},"pull_request":{"url":"x"}}` plainIssue := `{"number":14859,"state":"open","html_url":"https://github.com/o/r/issues/14859","repository":{"full_name":"o/r"}}` cases := []struct { @@ -426,6 +428,18 @@ func TestSearchLinkedPR_CountsCommitCommentAndTimelineReferences(t *testing.T) { wantNumber: 14656, wantState: prLinkStateMerged, }, + { + name: "cross-reference from a PR that only mentions the issue", + search: `[]`, + timeline: `[` + crossRef(mentionPR) + `]`, + }, + { + name: "mention-only PR is skipped, closing PR is chosen", + search: `[]`, + timeline: `[` + crossRef(mentionPR) + `,` + crossRef(closingPR) + `]`, + wantNumber: 14701, + wantState: prLinkStateOpen, + }, { name: "no reference anywhere", search: `[` + searchHit + `]`, From f87dd1e994da338ac0459498a44a79873d0b3d5d Mon Sep 17 00:00:00 2001 From: "hivecommons-hive[bot]" <280983584+hivecommons-hive[bot]@users.noreply.github.com> Date: Wed, 28 Oct 2026 14:59:28 +0000 Subject: [PATCH 2/5] changelog: fragment for #14974 Generated by changelog-fragment-guard from the PR title (#5675). Edit the wording freely, or replace this file with the no-changelog label if the change is not user-visible. Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Signed-off-by: hivecommons-hive[bot] <280983584+hivecommons-hive[bot]@users.noreply.github.com> --- changelog.d/fixed-14974.md | 1 + 1 file changed, 1 insertion(+) create mode 100644 changelog.d/fixed-14974.md diff --git a/changelog.d/fixed-14974.md b/changelog.d/fixed-14974.md new file mode 100644 index 0000000000..dfd0dec541 --- /dev/null +++ b/changelog.d/fixed-14974.md @@ -0,0 +1 @@ +- fix(dashboard): only link cross-referenced PRs that actually fix the issue (#14974) From 2e85793e63c00aeeb1a162a14c98ebe15e531a48 Mon Sep 17 00:00:00 2001 From: scanner <280983584+hivecommons-hive[bot]@users.noreply.github.com> Date: Wed, 28 Oct 2026 11:13:14 -0400 Subject: [PATCH 3/5] changelog: make the #14966 fragment a single entry bullet Signed-off-by: scanner <280983584+hivecommons-hive[bot]@users.noreply.github.com> --- changelog.d/fixed-14966-prlink-cross-reference-mentions.md | 2 +- changelog.d/fixed-14974.md | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) delete mode 100644 changelog.d/fixed-14974.md diff --git a/changelog.d/fixed-14966-prlink-cross-reference-mentions.md b/changelog.d/fixed-14966-prlink-cross-reference-mentions.md index 837c4e08b9..43906b967f 100644 --- a/changelog.d/fixed-14966-prlink-cross-reference-mentions.md +++ b/changelog.d/fixed-14966-prlink-cross-reference-mentions.md @@ -1 +1 @@ -The dashboard no longer marks an issue as Reviewing just because an open pull request mentions it; a timeline cross-reference now counts as the linked PR only when that PR's title or body closes the issue (Closes/Fixes/Resolves). +- The dashboard no longer marks an issue as Reviewing just because an open pull request mentions it; a timeline cross-reference now counts as the linked PR only when that PR's title or body closes the issue (Closes/Fixes/Resolves) ([#14966](https://github.com/hivecommons/hive/issues/14966)). diff --git a/changelog.d/fixed-14974.md b/changelog.d/fixed-14974.md deleted file mode 100644 index dfd0dec541..0000000000 --- a/changelog.d/fixed-14974.md +++ /dev/null @@ -1 +0,0 @@ -- fix(dashboard): only link cross-referenced PRs that actually fix the issue (#14974) From 23cd226fffb3807c5d7ba6ee292612a6d3aaa446 Mon Sep 17 00:00:00 2001 From: scanner <280983584+hivecommons-hive[bot]@users.noreply.github.com> Date: Wed, 28 Oct 2026 11:47:06 -0400 Subject: [PATCH 4/5] fix(dashboard): keep comment-only timeline PRs when gating on closing keywords MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit prClosesIssue rejected any cross-referencing PR whose title/body lacked a Closes/Fixes/Resolves keyword, which dropped PRs that reference the issue only from a PR comment — the case the timeline read exists for (#14859). Now a PR whose title/body never names the issue (bare #N, owner/repo#N, or issue URL) is kept, and the keyword gate applies only when the title/body does mention it without closing it. Add a timeline fixture with a populated, non-referencing title/body so the #14859 path exercises the gate rather than the empty-title/body fallback, and a prClosesIssue table test covering the mention forms. Hive-Fix-Attempt: 1/6 Signed-off-by: scanner <280983584+hivecommons-hive[bot]@users.noreply.github.com> --- src/pkg/dashboard/contribute_prlink.go | 44 +++++++++++++-- src/pkg/dashboard/contribute_prlink_test.go | 61 +++++++++++++++++++++ 2 files changed, 99 insertions(+), 6 deletions(-) diff --git a/src/pkg/dashboard/contribute_prlink.go b/src/pkg/dashboard/contribute_prlink.go index 164e903c85..6f1fdbf854 100644 --- a/src/pkg/dashboard/contribute_prlink.go +++ b/src/pkg/dashboard/contribute_prlink.go @@ -260,18 +260,50 @@ func crossReferencingPRs(ctx context.Context, gc *gh.Client, repo string, number // cheap and within a single request. const prLinkSearchPerPage = 10 -// prClosesIssue reports whether a timeline cross-referencing PR names the -// issue as a fix (Closes/Fixes/Resolves) in its title or body, so a PR that -// merely mentions the issue is not promoted as its linked PR. A source with -// no title or body (omitted by the API) is accepted, as in prReferencesIssue. +// prClosesIssue reports whether a timeline cross-referencing PR should count +// as the issue's linked PR. A PR whose title/body mentions the issue must name +// it as a fix (Closes/Fixes/Resolves), so a passing "see also #N" is not +// promoted. A PR whose title/body does not mention the issue at all reached +// the timeline through a PR comment (hivecommons/hive#14859), which is the +// case the timeline read exists for, so it is kept. A source with no title or +// body (omitted by the API) is accepted, as in prReferencesIssue. func prClosesIssue(iss *gh.Issue, repo string, number int) bool { - if iss.GetBody() == "" && iss.GetTitle() == "" { + title, body := iss.GetTitle(), iss.GetBody() + if title == "" && body == "" { return true } - _, ok := github.FindClosingKeywordReference(iss.GetTitle()+"\n"+iss.GetBody(), repo, repo, number) + text := title + "\n" + body + if !prMentionsIssue(text, repo, number) { + return true + } + _, ok := github.FindClosingKeywordReference(text, repo, repo, number) return ok } +// prMentionsIssue reports whether text names repo#number in any of the forms +// GitHub turns into a cross-reference: a bare "#N", "owner/repo#N", or the +// issue's URL. +func prMentionsIssue(text, repo string, number int) bool { + lower := strings.ToLower(text) + for _, form := range []string{ + strings.ToLower(fmt.Sprintf("%s#%d", repo, number)), + strings.ToLower(fmt.Sprintf("github.com/%s/issues/%d", repo, number)), + } { + for i := strings.Index(lower, form); i >= 0; { + end := i + len(form) + if end == len(lower) || lower[end] < '0' || lower[end] > '9' { + return true + } + next := strings.Index(lower[end:], form) + if next < 0 { + break + } + i = end + next + } + } + return prReferencesIssue(&gh.Issue{Body: &text}, number) +} + // prReferencesIssue guards against a coincidental number collision: the Search // "#N" match is broad, so confirm the PR actually names the issue as a reference // (Fixes/Closes/Resolves #N, or a bare #N mention) in its title or body before diff --git a/src/pkg/dashboard/contribute_prlink_test.go b/src/pkg/dashboard/contribute_prlink_test.go index 4b8add7ec5..3cae501690 100644 --- a/src/pkg/dashboard/contribute_prlink_test.go +++ b/src/pkg/dashboard/contribute_prlink_test.go @@ -396,6 +396,10 @@ func TestSearchLinkedPR_CountsCommitCommentAndTimelineReferences(t *testing.T) { openPR := `{"number":14656,"state":"open","html_url":"https://github.com/o/r/pull/14656","repository":{"full_name":"o/r"},"pull_request":{"url":"x"}}` mergedPR := `{"number":14656,"state":"closed","html_url":"https://github.com/o/r/pull/14656","repository":{"full_name":"o/r"},"pull_request":{"url":"x","merged_at":"2026-10-28T00:00:00Z"}}` otherRepoPR := `{"number":77,"state":"open","html_url":"https://github.com/x/y/pull/77","repository":{"full_name":"x/y"},"pull_request":{"url":"x"}}` + // A PR whose title/body is populated but never names the issue: it is on + // the timeline only because a PR comment mentioned the issue (#14859). + commentOnlyPR := `{"number":14656,"state":"open","title":"keep the header chips from overlapping the title","body":"Hive Agent","html_url":"https://github.com/o/r/pull/14656","repository":{"full_name":"o/r"},"pull_request":{"url":"x"}}` + commentOnlyMergedPR := `{"number":14656,"state":"closed","title":"keep the header chips from overlapping the title","body":"Hive Agent","html_url":"https://github.com/o/r/pull/14656","repository":{"full_name":"o/r"},"pull_request":{"url":"x","merged_at":"2026-10-28T00:00:00Z"}}` mentionPR := `{"number":14700,"state":"open","title":"unrelated work","body":"see also #13135 for context","html_url":"https://github.com/o/r/pull/14700","repository":{"full_name":"o/r"},"pull_request":{"url":"x"}}` closingPR := `{"number":14701,"state":"open","title":"fix it","body":"Closes #13135","html_url":"https://github.com/o/r/pull/14701","repository":{"full_name":"o/r"},"pull_request":{"url":"x"}}` plainIssue := `{"number":14859,"state":"open","html_url":"https://github.com/o/r/issues/14859","repository":{"full_name":"o/r"}}` @@ -428,6 +432,27 @@ func TestSearchLinkedPR_CountsCommitCommentAndTimelineReferences(t *testing.T) { wantNumber: 14656, wantState: prLinkStateMerged, }, + { + name: "PR comment reference only (title/body populated, not naming the issue)", + search: `[` + searchHit + `]`, + timeline: `[` + crossRef(commentOnlyPR) + `]`, + wantNumber: 14656, + wantState: prLinkStateOpen, + }, + { + name: "PR comment reference only from a merged PR", + search: `[]`, + timeline: `[` + crossRef(commentOnlyMergedPR) + `]`, + wantNumber: 14656, + wantState: prLinkStateMerged, + }, + { + name: "comment-only PR beats a later mention-only PR", + search: `[]`, + timeline: `[` + crossRef(commentOnlyPR) + `,` + crossRef(mentionPR) + `]`, + wantNumber: 14656, + wantState: prLinkStateOpen, + }, { name: "cross-reference from a PR that only mentions the issue", search: `[]`, @@ -484,6 +509,42 @@ func TestSearchLinkedPR_CountsCommitCommentAndTimelineReferences(t *testing.T) { } } +// TestPrClosesIssue pins the timeline gate: a PR whose title/body names the +// issue must do so with a closing keyword, while a PR whose title/body never +// names the issue reached the timeline via a PR comment and is kept (#14859). +func TestPrClosesIssue(t *testing.T) { + cases := []struct { + name string + title, body string + want bool + }{ + {"empty title and body", "", "", true}, + {"comment-only: title/body never name the issue", "keep the header chips from overlapping", "Hive Agent", true}, + {"closing keyword", "fix it", "Closes #13135", true}, + {"closing keyword, repo-qualified", "fix it", "Fixes o/r#13135", true}, + {"bare mention without keyword", "unrelated", "see also #13135 for context", false}, + {"repo-qualified mention without keyword", "unrelated", "see also o/r#13135", false}, + {"URL mention without keyword", "unrelated", "see https://github.com/o/r/issues/13135", false}, + {"mention in title without keyword", "follow-up to #13135", "", false}, + {"different issue number", "unrelated", "Closes #131350 and see #1313", true}, + {"URL for a different issue number", "unrelated", "see https://github.com/o/r/issues/131350", true}, + } + for _, tc := range cases { + t.Run(tc.name, func(t *testing.T) { + iss := &gh.Issue{} + if tc.title != "" { + iss.Title = gh.Ptr(tc.title) + } + if tc.body != "" { + iss.Body = gh.Ptr(tc.body) + } + if got := prClosesIssue(iss, "o/r", 13135); got != tc.want { + t.Fatalf("prClosesIssue(%q, %q) = %v, want %v", tc.title, tc.body, got, tc.want) + } + }) + } +} + // TestCrossReferencingPRs_PageCap pins the prLinkTimelineMaxPages bound: a // timeline that keeps advertising a next page is read at most that many // times, and the lookup keeps what it has read instead of walking to From 071a132788e670d32605ca7b0b253259636a3d37 Mon Sep 17 00:00:00 2001 From: scanner <280983584+hivecommons-hive[bot]@users.noreply.github.com> Date: Wed, 28 Oct 2026 12:06:32 -0400 Subject: [PATCH 5/5] fix(dashboard): gate search-path PR links on a closing keyword too Search.Issues indexes bare "#N" mentions, so a PR whose body says "see also #N" was still returned as the open linked PR via the search path even though the timeline path required Closes/Fixes/Resolves. Apply the same closing-keyword gate to search hits (searchHitClosesIssue), accept "(#N)"/"[#N]" as mentions in prReferencesIssue so a parenthesised bare mention is not misread as comment-only, refresh the searchLinkedPR doc comment, and narrow the changelog wording to match. Hive-Fix-Attempt: 2/6 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Signed-off-by: scanner <280983584+hivecommons-hive[bot]@users.noreply.github.com> --- ...d-14966-prlink-cross-reference-mentions.md | 2 +- src/pkg/dashboard/contribute_prlink.go | 54 ++++++++++++------- src/pkg/dashboard/contribute_prlink_test.go | 22 ++++++++ 3 files changed, 59 insertions(+), 19 deletions(-) diff --git a/changelog.d/fixed-14966-prlink-cross-reference-mentions.md b/changelog.d/fixed-14966-prlink-cross-reference-mentions.md index 43906b967f..6e3276c432 100644 --- a/changelog.d/fixed-14966-prlink-cross-reference-mentions.md +++ b/changelog.d/fixed-14966-prlink-cross-reference-mentions.md @@ -1 +1 @@ -- The dashboard no longer marks an issue as Reviewing just because an open pull request mentions it; a timeline cross-reference now counts as the linked PR only when that PR's title or body closes the issue (Closes/Fixes/Resolves) ([#14966](https://github.com/hivecommons/hive/issues/14966)). +- The dashboard no longer marks an issue as Reviewing just because an open pull request mentions it: a PR found by search or by a timeline cross-reference counts as the linked PR only when its title or body closes the issue (Closes/Fixes/Resolves); a PR that names the issue only in a PR comment is still linked ([#14966](https://github.com/hivecommons/hive/issues/14966)). diff --git a/src/pkg/dashboard/contribute_prlink.go b/src/pkg/dashboard/contribute_prlink.go index 6f1fdbf854..9fceb6e0f8 100644 --- a/src/pkg/dashboard/contribute_prlink.go +++ b/src/pkg/dashboard/contribute_prlink.go @@ -128,15 +128,18 @@ func (r *prLinkResolver) resolve(ctx context.Context, repo string, number int) * return status } -// searchLinkedPR asks GitHub which PR (if any) references this issue. It runs one +// searchLinkedPR asks GitHub which PR (if any) fixes this issue. It runs one // Search.Issues query scoped to the issue's repo, matching PRs that mention the -// issue number — GitHub indexes the Fixes/Closes/Resolves cross-reference as well -// as any plain "#N" body/title mention, so the closing PR is included. A merged -// PR wins over a merely-open one (the fix landed), so results are scanned for a -// merged hit first, then an open one. When the search yields no merged PR it also -// reads the issue's timeline, whose cross-referenced events catch a PR that names -// the issue in its body or a comment. A nil client or empty result is -// "no linked PR" (nil, nil) — never an error the caller must handle. +// issue number — GitHub indexes any plain "#N" body/title mention, so each hit +// is then checked for a closing keyword (Closes/Fixes/Resolves #N) in its +// title or body; a passing "see also #N" is not a linked PR. A merged PR wins +// over a merely-open one (the fix landed), so results are scanned for a merged +// hit first, then an open one. When the search yields no merged PR it also +// reads the issue's timeline, whose cross-referenced events catch a PR that +// names the issue only in a PR comment; a timeline PR whose title/body does +// mention the issue is held to the same closing-keyword rule (prClosesIssue). +// A nil client or empty result is "no linked PR" (nil, nil) — never an error +// the caller must handle. func searchLinkedPR(ctx context.Context, gc *gh.Client, repo string, number int) (*prLinkStatus, error) { if gc == nil || repo == "" || number <= 0 { return nil, nil @@ -160,7 +163,7 @@ func searchLinkedPR(ctx context.Context, gc *gh.Client, repo string, number int) if iss == nil || iss.PullRequestLinks == nil { continue // search can return issues too; keep only PRs } - if !prReferencesIssue(iss, number) { + if !searchHitClosesIssue(iss, repo, number) { continue } st, merged := prLinkCandidate(iss) @@ -173,7 +176,7 @@ func searchLinkedPR(ctx context.Context, gc *gh.Client, repo string, number int) } } - // The title/body check above cannot see a PR that names the issue only in + // The search above cannot see a PR that names the issue only in // a PR comment (hivecommons/hive#14859). GitHub records such a mention // as a cross-referenced event on the issue's timeline, so one timeline // read covers body and comment references. Commit-message references @@ -260,13 +263,28 @@ func crossReferencingPRs(ctx context.Context, gc *gh.Client, repo string, number // cheap and within a single request. const prLinkSearchPerPage = 10 +// searchHitClosesIssue reports whether a Search.Issues hit should count as +// the issue's linked PR. The "#N" search qualifier indexes bare mentions, so +// the hit must name the issue with a closing keyword (Closes/Fixes/Resolves) +// in its title or body; a passing "see also #N" is not promoted. A hit with +// no title or body (omitted by the API on some responses) is accepted, since +// the number qualifier already scoped it. +func searchHitClosesIssue(iss *gh.Issue, repo string, number int) bool { + title, body := iss.GetTitle(), iss.GetBody() + if title == "" && body == "" { + return true + } + _, ok := github.FindClosingKeywordReference(title+"\n"+body, repo, repo, number) + return ok +} + // prClosesIssue reports whether a timeline cross-referencing PR should count // as the issue's linked PR. A PR whose title/body mentions the issue must name // it as a fix (Closes/Fixes/Resolves), so a passing "see also #N" is not // promoted. A PR whose title/body does not mention the issue at all reached // the timeline through a PR comment (hivecommons/hive#14859), which is the // case the timeline read exists for, so it is kept. A source with no title or -// body (omitted by the API) is accepted, as in prReferencesIssue. +// body (omitted by the API) is accepted, as in searchHitClosesIssue. func prClosesIssue(iss *gh.Issue, repo string, number int) bool { title, body := iss.GetTitle(), iss.GetBody() if title == "" && body == "" { @@ -304,11 +322,11 @@ func prMentionsIssue(text, repo string, number int) bool { return prReferencesIssue(&gh.Issue{Body: &text}, number) } -// prReferencesIssue guards against a coincidental number collision: the Search -// "#N" match is broad, so confirm the PR actually names the issue as a reference -// (Fixes/Closes/Resolves #N, or a bare #N mention) in its title or body before -// treating it as the fix-PR. Missing body/title (search omits them on some -// responses) is treated as a match, since the number qualifier already scoped it. +// prReferencesIssue reports whether the PR's title or body names the issue +// with a bare "#N" mention (any keyword or none). It backs prMentionsIssue, +// which decides whether a timeline PR reached the issue through its own text +// or only through a PR comment. Missing body/title (the API omits them on +// some responses) is treated as a match. func prReferencesIssue(iss *gh.Issue, number int) bool { needle := fmt.Sprintf("#%d", number) body := iss.GetBody() @@ -318,8 +336,8 @@ func prReferencesIssue(iss *gh.Issue, number int) bool { } hay := title + "\n" + body for _, tok := range strings.Fields(hay) { - // Trim trailing punctuation so "#123." / "#123," still match. - tok = strings.TrimRight(tok, ".,);:") + // Trim surrounding punctuation so "#123." / "#123," / "(#123)" still match. + tok = strings.TrimRight(strings.TrimLeft(tok, "([<"), ".,);:]>") if tok == needle { return true } diff --git a/src/pkg/dashboard/contribute_prlink_test.go b/src/pkg/dashboard/contribute_prlink_test.go index 3cae501690..291afbe4b6 100644 --- a/src/pkg/dashboard/contribute_prlink_test.go +++ b/src/pkg/dashboard/contribute_prlink_test.go @@ -45,6 +45,8 @@ func TestPrReferencesIssue_TrailingPunctuation(t *testing.T) { {"Fixes #20,", 20}, {"See #30)", 30}, {"refs #50:", 50}, + {"follow-up (#60)", 60}, + {"see [#70]", 70}, } for _, tt := range tests { iss := &gh.Issue{Title: strPtr(""), Body: strPtr(tt.body)} @@ -458,6 +460,25 @@ func TestSearchLinkedPR_CountsCommitCommentAndTimelineReferences(t *testing.T) { search: `[]`, timeline: `[` + crossRef(mentionPR) + `]`, }, + { + name: "search hit from a PR that only mentions the issue", + search: `[` + mentionPR + `]`, + timeline: `[]`, + }, + { + name: "search hit with a closing keyword", + search: `[` + closingPR + `]`, + timeline: `[]`, + wantNumber: 14701, + wantState: prLinkStateOpen, + }, + { + name: "mention-only search hit is skipped, closing search hit is chosen", + search: `[` + mentionPR + `,` + closingPR + `]`, + timeline: `[]`, + wantNumber: 14701, + wantState: prLinkStateOpen, + }, { name: "mention-only PR is skipped, closing PR is chosen", search: `[]`, @@ -523,6 +544,7 @@ func TestPrClosesIssue(t *testing.T) { {"closing keyword", "fix it", "Closes #13135", true}, {"closing keyword, repo-qualified", "fix it", "Fixes o/r#13135", true}, {"bare mention without keyword", "unrelated", "see also #13135 for context", false}, + {"parenthesised mention without keyword", "unrelated", "follow-up (#13135)", false}, {"repo-qualified mention without keyword", "unrelated", "see also o/r#13135", false}, {"URL mention without keyword", "unrelated", "see https://github.com/o/r/issues/13135", false}, {"mention in title without keyword", "follow-up to #13135", "", false},