Skip to content
Merged
1 change: 1 addition & 0 deletions changelog.d/fixed-closed-by-cross-repo-pr-ref.md
Original file line number Diff line number Diff line change
@@ -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)).
2 changes: 1 addition & 1 deletion src/pkg/dashboard/api_repo_item_decision_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"):
Expand Down
27 changes: 27 additions & 0 deletions src/pkg/github/issue_link_state_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
4 changes: 2 additions & 2 deletions src/pkg/github/issue_stage_labels_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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},
},
}}})
Expand All @@ -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
Expand Down
18 changes: 18 additions & 0 deletions src/pkg/github/pr_supersession_sweep.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package github

import (
"context"
"fmt"
"net/url"
"strconv"
"strings"
"time"

Expand Down Expand Up @@ -470,11 +472,27 @@
if node.Number == currentPR || !node.Merged {
continue
}
if !sameRepoPullURL(node.URL, owner, repo, node.Number) {
continue
}
return supersessionCloser{Repo: displayRepo, Number: node.Number, URL: node.URL, MergedAt: node.MergedAt}, true
}
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 := ""
Expand Down
Loading