From 7ed6f0b085617588423ed76768be085ab06e0004 Mon Sep 17 00:00:00 2001 From: scanner <280983584+hivecommons-hive[bot]@users.noreply.github.com> Date: Thu, 29 Oct 2026 16:01:03 -0400 Subject: [PATCH 1/2] fix(github): ignore cross-repo PRs in closedByPullRequestsReferences GitHub may list a merged PR from another repository as a closer. The helper kept only the number, so consumers could link item.repo/pull/ to an unrelated PR. Skip nodes whose URL is not under the queried owner/repo (case-insensitive). Signed-off-by: scanner <280983584+hivecommons-hive[bot]@users.noreply.github.com> --- .../fixed-closed-by-cross-repo-pr-ref.md | 1 + src/pkg/github/issue_link_state_test.go | 27 +++++++++++++++++++ src/pkg/github/pr_supersession_sweep.go | 6 +++++ 3 files changed, 34 insertions(+) create mode 100644 changelog.d/fixed-closed-by-cross-repo-pr-ref.md diff --git a/changelog.d/fixed-closed-by-cross-repo-pr-ref.md b/changelog.d/fixed-closed-by-cross-repo-pr-ref.md new file mode 100644 index 0000000000..b69cf477f4 --- /dev/null +++ b/changelog.d/fixed-closed-by-cross-repo-pr-ref.md @@ -0,0 +1 @@ +- A merged pull request from another repository listed under `closedByPullRequestsReferences` is no longer reported as a same-repo closer, so tracker chips cannot link an issue to an unrelated PR ([#15494](https://github.com/hivecommons/hive/issues/15494)). diff --git a/src/pkg/github/issue_link_state_test.go b/src/pkg/github/issue_link_state_test.go index fbc567c958..bda8211501 100644 --- a/src/pkg/github/issue_link_state_test.go +++ b/src/pkg/github/issue_link_state_test.go @@ -85,3 +85,30 @@ func TestIssueLinkStateCloserLookupBestEffort(t *testing.T) { t.Fatalf("got %+v, want title/state kept and ClosedBy 0", got) } } + +// closedByPullRequestsReferences can include a merged PR from another +// repository; its number must never be reported as a same-repo closer. +func TestIssueLinkStateIgnoresCrossRepoCloser(t *testing.T) { + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method == http.MethodPost && strings.HasSuffix(r.URL.Path, "/graphql") { + fmt.Fprint(w, `{"data":{"repository":{"issue":{"closedByPullRequestsReferences":{"nodes":[`+ + `{"number":55,"url":"https://github.com/other/repo/pull/55","merged":true,"mergedAt":"2026-10-29T16:38:39Z"},`+ + `{"number":99,"url":"https://github.com/O/R/pull/99","merged":true,"mergedAt":"2026-10-29T16:38:39Z"}]}}}}}`) + return + } + if r.URL.Path == "/repos/o/r/issues/7" { + fmt.Fprint(w, `{"number":7,"title":"Closed one","state":"closed","state_reason":"completed"}`) + return + } + http.NotFound(w, r) + })) + defer ts.Close() + c := NewClientForTest(ts.URL, "o", []string{"r"}, slog.Default()) + got, err := c.IssueLinkState(context.Background(), "o", "r", 7, 0) + if err != nil { + t.Fatal(err) + } + if got.ClosedBy != 99 { + t.Fatalf("ClosedBy = %d, want 99 (cross-repo #55 ignored)", got.ClosedBy) + } +} diff --git a/src/pkg/github/pr_supersession_sweep.go b/src/pkg/github/pr_supersession_sweep.go index 55c34c130b..5344c34491 100644 --- a/src/pkg/github/pr_supersession_sweep.go +++ b/src/pkg/github/pr_supersession_sweep.go @@ -466,10 +466,16 @@ func (c *Client) closedByPullRequestReference(ctx context.Context, owner, repo s return supersessionCloser{}, false } displayRepo := owner + "/" + repo + // GitHub can list a merged PR from another repository; only a same-repo + // PR may be named by number. + prefix := strings.ToLower("https://github.com/"+displayRepo) + "/pull/" for _, node := range resp.Data.Repository.Issue.ClosedByPullRequestsReferences.Nodes { if node.Number == currentPR || !node.Merged { continue } + if !strings.HasPrefix(strings.ToLower(node.URL), prefix) { + continue + } return supersessionCloser{Repo: displayRepo, Number: node.Number, URL: node.URL, MergedAt: node.MergedAt}, true } return supersessionCloser{}, false From 660ad91985228cbda0438b0e1ec6d64ad9a6d043 Mon Sep 17 00:00:00 2001 From: scanner <280983584+hivecommons-hive[bot]@users.noreply.github.com> Date: Thu, 29 Oct 2026 16:42:22 -0400 Subject: [PATCH 2/2] fix(github): match same-repo closers by URL path, not github.com prefix The closer filter compared against a hardcoded https://github.com prefix, which rejected GitHub Enterprise URLs and the dashboard test fixture's placeholder URL (TestDelegatedAlreadyFixedClosesInsteadOfAdopting). Compare the URL path /owner/repo/pull/N instead and give the fixtures realistic same-repo URLs. Signed-off-by: scanner <280983584+hivecommons-hive[bot]@users.noreply.github.com> --- .../dashboard/api_repo_item_decision_test.go | 2 +- src/pkg/github/issue_stage_labels_test.go | 4 ++-- src/pkg/github/pr_supersession_sweep.go | 20 +++++++++++++++---- 3 files changed, 19 insertions(+), 7 deletions(-) diff --git a/src/pkg/dashboard/api_repo_item_decision_test.go b/src/pkg/dashboard/api_repo_item_decision_test.go index 7309a518c5..15a1151288 100644 --- a/src/pkg/dashboard/api_repo_item_decision_test.go +++ b/src/pkg/dashboard/api_repo_item_decision_test.go @@ -103,7 +103,7 @@ func newRepoItemDecisionServer(t *testing.T, m *repoItemDecisionMock) *Server { http.NotFound(w, r) return } - _ = json.NewEncoder(w).Encode(map[string]any{"data": map[string]any{"repository": map[string]any{"issue": map[string]any{"closedByPullRequestsReferences": map[string]any{"nodes": []map[string]any{{"number": m.fixedIssueClosedBy, "url": "https://example.test/pr/" + strconv.Itoa(m.fixedIssueClosedBy), "merged": true, "mergedAt": "2026-10-28T11:00:00Z"}}}}}}}) + _ = json.NewEncoder(w).Encode(map[string]any{"data": map[string]any{"repository": map[string]any{"issue": map[string]any{"closedByPullRequestsReferences": map[string]any{"nodes": []map[string]any{{"number": m.fixedIssueClosedBy, "url": "https://github.com/testorg/testrepo/pull/" + strconv.Itoa(m.fixedIssueClosedBy), "merged": true, "mergedAt": "2026-10-28T11:00:00Z"}}}}}}}) case r.Method == http.MethodGet && m.fixedIssueClosedBy > 0 && strings.HasSuffix(path, "/pulls/"+strconv.Itoa(m.fixedIssueClosedBy)): _ = json.NewEncoder(w).Encode(map[string]any{"number": m.fixedIssueClosedBy, "state": "closed", "merged": true, "merged_at": "2026-10-28T11:00:00Z", "merge_commit_sha": "25de3ba24fa0c0ffee0000000000000000000000", "user": map[string]any{"login": "hive[bot]", "type": "Bot"}, "head": map[string]any{"sha": "cafecafecafecafecafecafecafecafecafecafe"}, "base": map[string]any{"ref": "main"}}) case r.Method == http.MethodGet && strings.HasSuffix(path, "/pulls/90"): diff --git a/src/pkg/github/issue_stage_labels_test.go b/src/pkg/github/issue_stage_labels_test.go index 5bbdca1ed6..cf230ca6b0 100644 --- a/src/pkg/github/issue_stage_labels_test.go +++ b/src/pkg/github/issue_stage_labels_test.go @@ -106,7 +106,7 @@ func newIssueStageServer(t *testing.T) *issueStageServer { "state": "OPEN", "baseRefName": base, "body": s.prBodies[pr], - "url": "https://x/pr/" + strconv.Itoa(pr), + "url": "https://github.com/acme/widgets/pull/" + strconv.Itoa(pr), "author": map[string]any{"login": author}, }, }}}) @@ -117,7 +117,7 @@ func newIssueStageServer(t *testing.T) *issueStageServer { s.mu.Unlock() nodes := []map[string]any{} if pr > 0 { - nodes = append(nodes, map[string]any{"number": pr, "url": "https://x/pr/" + strconv.Itoa(pr), "merged": true}) + nodes = append(nodes, map[string]any{"number": pr, "url": "https://github.com/acme/widgets/pull/" + strconv.Itoa(pr), "merged": true}) } _ = json.NewEncoder(w).Encode(map[string]any{"data": map[string]any{"repository": map[string]any{"issue": map[string]any{"closedByPullRequestsReferences": map[string]any{"nodes": nodes}}}}}) return diff --git a/src/pkg/github/pr_supersession_sweep.go b/src/pkg/github/pr_supersession_sweep.go index 5344c34491..d69bd95bc8 100644 --- a/src/pkg/github/pr_supersession_sweep.go +++ b/src/pkg/github/pr_supersession_sweep.go @@ -3,6 +3,8 @@ package github import ( "context" "fmt" + "net/url" + "strconv" "strings" "time" @@ -466,14 +468,11 @@ func (c *Client) closedByPullRequestReference(ctx context.Context, owner, repo s return supersessionCloser{}, false } displayRepo := owner + "/" + repo - // GitHub can list a merged PR from another repository; only a same-repo - // PR may be named by number. - prefix := strings.ToLower("https://github.com/"+displayRepo) + "/pull/" for _, node := range resp.Data.Repository.Issue.ClosedByPullRequestsReferences.Nodes { if node.Number == currentPR || !node.Merged { continue } - if !strings.HasPrefix(strings.ToLower(node.URL), prefix) { + if !sameRepoPullURL(node.URL, owner, repo, node.Number) { continue } return supersessionCloser{Repo: displayRepo, Number: node.Number, URL: node.URL, MergedAt: node.MergedAt}, true @@ -481,6 +480,19 @@ func (c *Client) closedByPullRequestReference(ctx context.Context, owner, repo s return supersessionCloser{}, false } +// sameRepoPullURL reports whether a PR URL from closedByPullRequestsReferences +// names pull request number in owner/repo. GitHub can list a merged PR from +// another repository there, so only a same-repo PR may be named by number. +// The host is ignored so GitHub Enterprise URLs compare the same way. +func sameRepoPullURL(rawURL, owner, repo string, number int) bool { + u, err := url.Parse(rawURL) + if err != nil { + return false + } + want := "/" + owner + "/" + repo + "/pull/" + strconv.Itoa(number) + return strings.EqualFold(strings.TrimSuffix(u.Path, "/"), want) +} + func (c *Client) issueClosingCommit(ctx context.Context, owner, repo string, issue int) (string, error) { opts := &gh.ListOptions{PerPage: 100} latest := ""