diff --git a/changelog.d/fixed-tracker-row-closed-issue.md b/changelog.d/fixed-tracker-row-closed-issue.md new file mode 100644 index 0000000000..3bd1256a99 --- /dev/null +++ b/changelog.d/fixed-tracker-row-closed-issue.md @@ -0,0 +1 @@ +- Activity Monitor: a PR whose linked issue is already closed keeps that issue as the row head (struck through, `closed` chip) instead of promoting the PR into the issue slot; when another merged PR closed the issue the chip reads `closed by #N` and links to it (#15232). diff --git a/src/pkg/dashboard/merged_ledger.go b/src/pkg/dashboard/merged_ledger.go index db30d13fed..bfee40ada8 100644 --- a/src/pkg/dashboard/merged_ledger.go +++ b/src/pkg/dashboard/merged_ledger.go @@ -347,6 +347,26 @@ func (l *MergedLedger) Summary(now time.Time, loc *time.Location) StageTrackerMe return out } +// ClosedBy returns the newest merged PR in repo recorded as nested under +// issue, other than exclude (0 when none): the PR whose merge closed the +// issue out from under an open PR that still names it (the tracker's +// "closed by #N" chip, hivecommons/hive#15232). +func (l *MergedLedger) ClosedBy(repo string, issue, exclude int) int { + if l == nil || issue <= 0 { + return 0 + } + repo = strings.ToLower(strings.TrimSpace(repo)) + l.mu.Lock() + defer l.mu.Unlock() + for i := len(l.entries) - 1; i >= 0; i-- { + e := l.entries[i] + if e.Issue == issue && e.Number != exclude && strings.EqualFold(e.Repo, repo) { + return e.Number + } + } + return 0 +} + // Len is the number of listed (unpruned) entries. func (l *MergedLedger) Len() int { l.mu.Lock() diff --git a/src/pkg/dashboard/stage_tracker.go b/src/pkg/dashboard/stage_tracker.go index 9a3b44f7f6..3cf3486a2a 100644 --- a/src/pkg/dashboard/stage_tracker.go +++ b/src/pkg/dashboard/stage_tracker.go @@ -475,11 +475,15 @@ type StageTrackerItem struct { // orphan (hivecommons/hive#13544). LinkedIssues []StageTrackerLinkedIssue `json:"linked_issues,omitempty"` // ClosedIssue is set on a PR that stands as its own row because every - // issue it closes is already closed: the row is anchored on the PR (its - // number and title lead, its stage drives the strip, its timestamps - // sort it) and the closed issue is a secondary `closes #N · closed` - // chip. StateReason "not_planned" adds an "issue closed (not planned)" - // chip so the reader can tell the PR may be moot (hivecommons/hive#14655). + // issue it closes is already closed: the PR's stage drives the strip + // and its timestamps sort it, and the row sinks to the bottom of its + // column (hivecommons/hive#14655). The closed issue still leads the + // row in the issue slot — struck through, with a `closed` chip, or + // `closed by #N` when ClosedBy names the merged PR that closed it + // (hivecommons/hive#15232) — exactly as a soft-linked closed issue + // does; the PR never takes the issue slot itself. StateReason + // "not_planned" adds an "issue closed (not planned)" chip so the reader + // can tell the PR may be moot. ClosedIssue *StageTrackerLinkedIssue `json:"closed_issue,omitempty"` // LastOperatorAction is the newest owner row action recorded for the // item (approve, give-direction, hold, let-hive-decide, …) with what @@ -504,6 +508,13 @@ type StageTrackerLinkedIssue struct { // StateReason is GitHub's stateReason for a closed issue, lower-cased // ("completed", "not_planned", "duplicate"); "" when unknown. StateReason string `json:"state_reason,omitempty"` + // ClosedBy is, on a closed issue, the number of the merged pull request + // in the same repo that closed it when that PR is not the one carrying + // this link (the merged ledger's record of what it was nested under); + // 0 when unknown. The row's chip reads `closed by #N` so a PR still + // open against an issue another PR already delivered reads as the + // duplicate it is (hivecommons/hive#15232). + ClosedBy int `json:"closed_by,omitempty"` // Listed is true when the issue has its own row in this response; the // PR is then nested under it and never drawn as a top-level row. Listed bool `json:"listed,omitempty"` @@ -2040,6 +2051,7 @@ func (s *Server) buildStageTracker(status *StatusPayload, store *stagelabels.Sto s.applyOperatorActions(resp.Items, now) resp.NeedsHuman, resp.OnHold = stageTrackerHumanCounts(resp.Items) stageTrackerResolveLinkedPRs(resp.Items) + stageTrackerMarkClosedBy(resp.Items, s.mergedLedger().ClosedBy) stageTrackerResolveActors(resp.Items) sort.SliceStable(resp.Items, stageTrackerLess(resp.Items)) return resp @@ -2831,10 +2843,12 @@ func stageTrackerResolveLinkedPRs(items []StageTrackerItem) { // row re-anchors around, or nil. A PR nested under a listed issue, a PR // with an open closing link, and a PR whose links are all soft (`Refs #N`) // or of unknown state keep the issue slot as is; only a PR whose every -// closing link names a closed issue is drawn as the row's own headline, -// with the first closed issue as its secondary chip -// (hivecommons/hive#14655). The PR's stage, modifiers and timestamps are -// untouched: the issue closing is not a regression of the PR. +// closing link names a closed issue is re-anchored: its own stage and +// timestamps drive the row, which sinks in its column, and the first closed +// issue is named in ClosedIssue (hivecommons/hive#14655). The closed issue +// still leads the row in the issue slot (hivecommons/hive#15232). The PR's +// stage, modifiers and timestamps are untouched: the issue closing is not a +// regression of the PR. func stageTrackerClosedIssueAnchor(pr StageTrackerItem) *StageTrackerLinkedIssue { if pr.Kind != "pr" || pr.NestedUnder != 0 { return nil @@ -2862,3 +2876,32 @@ func stageTrackerClosedIssueAnchor(pr StageTrackerItem) *StageTrackerLinkedIssue out := *closed return &out } + +// stageTrackerMarkClosedBy names, on every closed closing link a PR row +// carries (and on its ClosedIssue), the merged pull request that closed +// the issue when it is another PR: closedBy(repo, issue, exclude) is the +// merged ledger's lookup (MergedLedger.ClosedBy), exclude the PR carrying +// the link so a PR is never reported as closing its own issue. A link +// whose closer is unknown, or whose issue is open, is left alone +// (hivecommons/hive#15232). +func stageTrackerMarkClosedBy(items []StageTrackerItem, closedBy func(repo string, issue, exclude int) int) { + if closedBy == nil { + return + } + for i := range items { + pr := &items[i] + if pr.Kind != "pr" { + continue + } + for j := range pr.LinkedIssues { + li := &pr.LinkedIssues[j] + if li.State != "closed" || li.ClosedBy != 0 { + continue + } + li.ClosedBy = closedBy(pr.Repo, li.Number, pr.Number) + } + if ci := pr.ClosedIssue; ci != nil && ci.State == "closed" && ci.ClosedBy == 0 { + ci.ClosedBy = closedBy(pr.Repo, ci.Number, pr.Number) + } + } +} diff --git a/src/pkg/dashboard/stage_tracker_closed_by_test.go b/src/pkg/dashboard/stage_tracker_closed_by_test.go new file mode 100644 index 0000000000..1eff9819c9 --- /dev/null +++ b/src/pkg/dashboard/stage_tracker_closed_by_test.go @@ -0,0 +1,119 @@ +package dashboard + +import ( + "testing" + "time" + + "github.com/hivecommons/hive/pkg/github" + "github.com/hivecommons/hive/pkg/stagelabels" +) + +// hivecommons/hive#15232: a PR whose closing link names an issue that was +// closed before the tracker ever listed it (the issue is not in the +// snapshot at all) keeps the issue in its linked_issues with its closed +// state — the SPA draws it in the issue slot — and, when the merged ledger +// knows another PR merged under that issue, names it as the closer on both +// the link and closed_issue. A PR never reads as the closer of its own +// issue. +func TestStageTrackerClosedIssueNamesClosingPR(t *testing.T) { + now := time.Date(2026, 10, 28, 21, 0, 0, 0, time.UTC) + const issueNum, prNum, otherPR = 15173, 15191, 15181 + tests := []struct { + name string + ledger []MergedLedgerEntry + wantBy int + }{ + {name: "closed by another merged PR", ledger: []MergedLedgerEntry{{Repo: "hivecommons/hive", Number: otherPR, Issue: issueNum, MergedAt: now.Add(-time.Hour)}}, wantBy: otherPR}, + {name: "closer unknown", wantBy: 0}, + {name: "ledger names only this PR", ledger: []MergedLedgerEntry{{Repo: "hivecommons/hive", Number: prNum, Issue: issueNum, MergedAt: now.Add(-time.Hour)}}, wantBy: 0}, + {name: "same issue number in another repo", ledger: []MergedLedgerEntry{{Repo: "hivecommons/other", Number: otherPR, Issue: issueNum, MergedAt: now.Add(-time.Hour)}}, wantBy: 0}, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + s := newTestServer() + store := stagelabels.NewStore("", func() time.Time { return now }) + s.stageStore = store + store.Observe(stagelabels.Key("hivecommons/hive", prNum), stagelabels.ReadyForHumanMerge, "contributor-lane:workflow-path:human-approved@clubanderson") + for _, e := range tt.ledger { + s.mergedLedger().Record(e, now) + } + + status := minimalPayload() + status.HiveID = "hv-test" + // The issue is already closed and absent from the snapshot: only + // the PR's closing reference knows it. + status.Repos = []FrontendRepo{{Name: "hive", Full: "hivecommons/hive", + OpenPrs: []any{FrontendPR{PullRequest: github.PullRequest{Number: prNum, Title: "Let hive decide on a ready-for-human-merge PR", Author: "clubanderson", + Labels: []string{"stage/090-ready-for-human-merge"}, CreatedAt: now.Add(-4 * time.Hour), UpdatedAt: now.Add(-time.Hour), + LinkedIssues: []github.PRLinkedIssue{{Number: issueNum, Repo: "hivecommons/hive", Title: "Sweep merges approved PRs", State: "CLOSED", StateReason: "COMPLETED"}}}}}}} + s.UpdateStatus(status) + resp := s.buildStageTracker(status, store, now) + + pr := trackerItem(t, resp, "pr", prNum) + if len(pr.LinkedIssues) != 1 || pr.LinkedIssues[0].Number != issueNum || pr.LinkedIssues[0].State != "closed" || pr.LinkedIssues[0].Title == "" { + t.Fatalf("linked_issues = %+v, want the closed issue #%d with its title so the issue slot can name it", pr.LinkedIssues, issueNum) + } + if pr.LinkedIssues[0].ClosedBy != tt.wantBy { + t.Fatalf("linked_issues[0].closed_by = %d, want %d", pr.LinkedIssues[0].ClosedBy, tt.wantBy) + } + if pr.ClosedIssue == nil || pr.ClosedIssue.Number != issueNum || pr.ClosedIssue.ClosedBy != tt.wantBy { + t.Fatalf("closed_issue = %+v, want #%d closed by %d", pr.ClosedIssue, issueNum, tt.wantBy) + } + }) + } +} + +func TestStageTrackerMarkClosedBy(t *testing.T) { + closers := map[string]int{"acme/console#496": 500, "acme/console#7": 9} + lookup := func(repo string, issue, exclude int) int { + if n := closers[repo+"#"+itoa(issue)]; n != exclude { + return n + } + return 0 + } + items := []StageTrackerItem{ + // An issue row is never touched. + {Kind: "issue", Repo: "acme/console", Number: 496}, + // Closed link, closed by another PR: named on the link and the anchor. + {Kind: "pr", Repo: "acme/console", Number: 501, LinkedIssues: []StageTrackerLinkedIssue{{Number: 496, State: "closed"}}, ClosedIssue: &StageTrackerLinkedIssue{Number: 496, State: "closed"}}, + // The row's own PR is the recorded closer: left at 0. + {Kind: "pr", Repo: "acme/console", Number: 500, LinkedIssues: []StageTrackerLinkedIssue{{Number: 496, State: "closed"}}}, + // An open link and an already-named closer are left alone. + {Kind: "pr", Repo: "acme/console", Number: 502, LinkedIssues: []StageTrackerLinkedIssue{{Number: 7, State: "open"}, {Number: 496, State: "closed", ClosedBy: 42}}}, + } + stageTrackerMarkClosedBy(items, lookup) + if items[1].LinkedIssues[0].ClosedBy != 500 || items[1].ClosedIssue.ClosedBy != 500 { + t.Fatalf("closed by another PR: link %+v anchor %+v", items[1].LinkedIssues[0], items[1].ClosedIssue) + } + if items[2].LinkedIssues[0].ClosedBy != 0 { + t.Fatalf("a PR must not be its own issue's closer: %+v", items[2].LinkedIssues[0]) + } + if items[3].LinkedIssues[0].ClosedBy != 0 || items[3].LinkedIssues[1].ClosedBy != 42 { + t.Fatalf("open link / pre-named closer changed: %+v", items[3].LinkedIssues) + } + // A nil lookup is a no-op, not a panic. + stageTrackerMarkClosedBy(items, nil) +} + +func TestMergedLedgerClosedBy(t *testing.T) { + l := newMergedLedger("") + l.Record(MergedLedgerEntry{Repo: "acme/console", Number: 500, Issue: 496, MergedAt: mergedTestNow.Add(-2 * time.Hour)}, mergedTestNow) + l.Record(MergedLedgerEntry{Repo: "acme/console", Number: 503, Issue: 496, MergedAt: mergedTestNow.Add(-time.Hour)}, mergedTestNow) + l.Record(MergedLedgerEntry{Repo: "acme/console", Number: 504, MergedAt: mergedTestNow.Add(-time.Minute)}, mergedTestNow) + if got := l.ClosedBy("ACME/Console", 496, 0); got != 503 { + t.Fatalf("newest closer = %d, want 503", got) + } + if got := l.ClosedBy("acme/console", 496, 503); got != 500 { + t.Fatalf("excluding the newest falls back to the earlier closer: %d, want 500", got) + } + if got := l.ClosedBy("acme/console", 497, 0); got != 0 { + t.Fatalf("unknown issue = %d, want 0", got) + } + if got := l.ClosedBy("acme/other", 496, 0); got != 0 { + t.Fatalf("other repo = %d, want 0", got) + } + var nilLedger *MergedLedger + if got := nilLedger.ClosedBy("acme/console", 496, 0); got != 0 { + t.Fatalf("nil ledger = %d, want 0", got) + } +} diff --git a/src/pkg/dashboard/stage_tracker_motion_test.go b/src/pkg/dashboard/stage_tracker_motion_test.go index b26d3dd830..f5fc3f8d02 100644 --- a/src/pkg/dashboard/stage_tracker_motion_test.go +++ b/src/pkg/dashboard/stage_tracker_motion_test.go @@ -466,6 +466,8 @@ func TestStageTrackerMotionRowStamp(t *testing.T) { jsFunc(t, html, "stageTrackerRowToolsHtml"), jsFunc(t, html, "stageTrackerRowHtml"), jsFunc(t, html, "stageTrackerPRIssueSlot"), + jsFunc(t, html, "stageTrackerClosedChipHtml"), + jsFunc(t, html, "stageTrackerItemURL"), }, "\n") + ` const now = Date.parse('2026-01-01T12:00:00Z'); const stages = [{ number: 10, label: 'Actionable', short: 'Actionable' }, { number: 20, label: 'Claimed', short: 'Claimed' }, { number: 30, label: 'PR in progress', short: 'PR in progress' }, { number: 50, label: 'Review pending', short: 'CI / Review' }, { number: 80, label: 'Awaiting merge admission', short: 'Merge gate' }, { number: 110, label: 'Merged', short: 'Merged' }]; @@ -593,6 +595,8 @@ func TestStageTrackerMotionPreviewSample(t *testing.T) { jsFunc(t, html, "stageTrackerRowToolsHtml"), jsFunc(t, html, "stageTrackerRowHtml"), jsFunc(t, html, "stageTrackerPRIssueSlot"), + jsFunc(t, html, "stageTrackerClosedChipHtml"), + jsFunc(t, html, "stageTrackerItemURL"), jsFunc(t, html, "stageTrackerItemKey"), jsFunc(t, html, "stageTrackerMoveAttrs"), jsFunc(t, html, "stageTrackerColIndex"), diff --git a/src/pkg/dashboard/stage_tracker_repo_grouping_test.go b/src/pkg/dashboard/stage_tracker_repo_grouping_test.go index 5c83229262..8b5289bc26 100644 --- a/src/pkg/dashboard/stage_tracker_repo_grouping_test.go +++ b/src/pkg/dashboard/stage_tracker_repo_grouping_test.go @@ -185,6 +185,8 @@ func stageTrackerRepoGroupingHarness(t *testing.T, html string) string { jsFunc(t, html, "stageTrackerRowToolsHtml"), jsFunc(t, html, "stageTrackerRowHtml"), jsFunc(t, html, "stageTrackerPRIssueSlot"), + jsFunc(t, html, "stageTrackerClosedChipHtml"), + jsFunc(t, html, "stageTrackerItemURL"), jsFunc(t, html, "stageTrackerItemKey"), jsFunc(t, html, "stageTrackerMoveAttrs"), jsFunc(t, html, "stageTrackerNeedsAttention"), diff --git a/src/pkg/dashboard/stage_tracker_ui_test.go b/src/pkg/dashboard/stage_tracker_ui_test.go index 77b1e6672e..f84cfc8c41 100644 --- a/src/pkg/dashboard/stage_tracker_ui_test.go +++ b/src/pkg/dashboard/stage_tracker_ui_test.go @@ -194,6 +194,8 @@ func stageTrackerRowsPreludeJS(t *testing.T, html string) string { jsFunc(t, html, "stageTrackerRowToolsHtml"), jsFunc(t, html, "stageTrackerRowHtml"), jsFunc(t, html, "stageTrackerPRIssueSlot"), + jsFunc(t, html, "stageTrackerClosedChipHtml"), + jsFunc(t, html, "stageTrackerItemURL"), jsFunc(t, html, "stageTrackerItemKey"), jsFunc(t, html, "stageTrackerMoveAttrs"), jsFunc(t, html, "stageTrackerNeedsAttention"), @@ -629,6 +631,32 @@ assert.ok(!row.includes('ham-no-issue-t') && !/]*title=/.te row = stageTrackerRowHtml({ repo: 'acme/console', number: 111, kind: 'pr', title: 'Docs', stage: 95, linked_issues: [{ number: 13409, state: 'closed', url: 'https://x/13409' }] }, stages, ctx); assert.strictEqual(lead(row), '#13409 (closed issue) closed', lead(row)); assert.ok(row.includes('(closed issue) closed'), row); +// hivecommons/hive#15232: a PR whose closing link names a closed issue +// (closed_issue set by the server, hivecommons/hive#14655) still puts the +// ISSUE in the left slot — struck through under its chip — and itself in the +// PR column, exactly like the soft-linked case above; the PR never leads. +// When the server names the merged PR that closed the issue, the chip reads +// "closed by #N" and links to that PR. +row = stageTrackerRowHtml({ repo: 'acme/console', number: 15191, kind: 'pr', title: 'Let hive decide', url: 'https://x/acme/console/pull/15191', stage: 90, author: 'clubanderson', author_kind: 'human', + linked_issues: [{ number: 15173, state: 'closed', state_reason: 'completed', title: 'Sweep merges approved PRs', url: 'https://x/acme/console/issues/15173', closed_by: 15181 }], + closed_issue: { number: 15173, state: 'closed', state_reason: 'completed', title: 'Sweep merges approved PRs', url: 'https://x/acme/console/issues/15173', closed_by: 15181 } }, stages, ctx); +assert.strictEqual(lead(row), '#15173 Sweep merges approved PRs closed by #15181', 'closed issue leads the row, with its closer: ' + lead(row)); +assert.ok(/
/.test(row) && /]*>#15173<\/a>/.test(row), 'struck-through issue link in the slot: ' + row); +assert.ok(/]*>closed by #15181<\/a>/.test(row), 'closed-by chip links the merged PR: ' + row); +assert.ok(!row.includes('ham-head-pr-anchor') && !row.includes('closes '), 'the PR no longer takes the issue slot: ' + row); +assert.ok(prCol(row).length === 1 && prCol(row)[0].includes('#15191') && prCol(row)[0].includes('Let hive decide'), 'PR sits in the PR column: ' + prCol(row)); +assert.ok(!row.includes('ham-closed-not-planned'), 'completed close: no moot chip'); +// Closer unknown: a plain "closed" chip; a not-planned close adds the moot chip. +row = stageTrackerRowHtml({ repo: 'acme/console', number: 15191, kind: 'pr', title: 'Let hive decide', stage: 90, + linked_issues: [{ number: 15173, state: 'closed', state_reason: 'not_planned', title: 'Sweep', url: 'https://x/15173' }], + closed_issue: { number: 15173, state: 'closed', state_reason: 'not_planned', title: 'Sweep', url: 'https://x/15173' } }, stages, ctx); +assert.strictEqual(lead(row), '#15173 Sweep closed issue closed (not planned)', lead(row)); +assert.ok(row.includes('closed closed'); +assert.deepStrictEqual(stageTrackerPRIssueSlot({ number: 500, linked_issues: [{ number: 496, state: 'closed', title: 'C', url: 'u', closed_by: 501 }] }), { number: 496, title: 'C', url: 'u', closed: true, placeholder: '', closed_by: 501 }, 'closed_by rides the slot'); +assert.strictEqual(stageTrackerItemURL('acme/console', 501, 'pull', 'https://ghe.example/acme/console/pull/500'), 'https://ghe.example/acme/console/pull/501', 'closer URL follows the sibling host'); +assert.strictEqual(stageTrackerItemURL('acme/console', 501, 'pull', ''), 'https://github.com/acme/console/pull/501'); // A linked issue of unknown state that is not listed still goes in the issue slot as a link, no chip; a missing title is said so. row = stageTrackerRowHtml({ repo: 'acme/console', number: 112, kind: 'pr', title: 'Fix', stage: 50, linked_issues: [{ number: 77, url: 'https://x/77' }] }, stages, ctx); assert.strictEqual(lead(row), '#77 (title unavailable)', lead(row)); diff --git a/src/pkg/dashboard/static/index.html b/src/pkg/dashboard/static/index.html index 3a0ec9e28f..6d00568895 100644 --- a/src/pkg/dashboard/static/index.html +++ b/src/pkg/dashboard/static/index.html @@ -1455,11 +1455,10 @@ .ham-issue-closed .ham-ref, .ham-issue-closed .ham-title { color: var(--text-faint); text-decoration: line-through; } .ham-issue-closed .ham-no-issue-t { text-decoration: none; } .ham-issue-closed-chip { flex: 0 0 auto; margin-left: var(--sp-1); } - /* PR-anchored row (every issue it closes is closed, PR still open): the PR leads at full width; the closed issue is a muted chip. */ - .ham-head-pr-anchor .ham-ref { display: inline-flex; align-items: center; gap: var(--sp-1); } - .ham-head-pr-anchor .ham-closed-issue-ref { color: var(--text-faint); text-decoration: none; } - .ham-head-pr-anchor .ham-closed-issue-ref:hover { color: var(--text); } - .ham-head-pr-anchor .ham-closed-not-planned { color: var(--text-faint); font-style: italic; } + /* The closed issue's chip may link to the merged PR that closed it ("closed by #N"); a not-planned close adds an italic "may be moot" chip. */ + .ham-issue-closed a.ham-issue-closed-chip { color: var(--text-faint); text-decoration: none; } + .ham-issue-closed a.ham-issue-closed-chip:hover { color: var(--text); } + .ham-issue-closed .ham-closed-not-planned { color: var(--text-faint); font-style: italic; } /* Issue slot naming an issue the PR only refers to (`Refs #N`, a `(#N, part 1)` title): a muted "refs" chip tells it from a closing link. */ .ham-issue-refs-chip { flex: 0 0 auto; margin-left: var(--sp-1); font-style: italic; } /* Repo chip before the number: monospace, tinted per repo from the @@ -15710,9 +15709,13 @@

Where to get help

// (no issue, or the Pull requests view) puts the issue it closes — or // a muted "no linked issue" placeholder — on the left and names // itself in the PR column, exactly where a covering PR sits on an - // issue row. The one exception is a PR whose every closing link is a - // closed issue (closed_issue set): that row is the PR's, so the PR - // leads at full width and the closed issue is a chip. + // issue row. That holds when the issue is already closed too + // (closed_issue set, hivecommons/hive#14655): the issue still leads, + // struck through with a `closed` chip — `closed by #N` when the + // server knows the merged PR that closed it, so a duplicate fix reads + // as one (hivecommons/hive#15232) — and the PR stays in the PR column + // rather than taking the issue slot. A not-planned close adds a chip + // saying the PR may be moot. // The repo chip (when on) leads the row, before the issue slot's #N. const chip = ctx.repoChips ? stageTrackerRepoChipHtml(item.repo, ctx) : ''; let leadHtml; @@ -15725,23 +15728,6 @@

Where to get help

${typeof stageTrackerLinkedElsewhereHtml === 'function' ? stageTrackerLinkedElsewhereHtml(item) : ''} ${item.is_tracker ? `tracker${item.children && item.children.total ? ' ' + Number(item.children.completed) + '/' + Number(item.children.total) : ''}` : ''}
`; - } else if (item.closed_issue && Number(item.closed_issue.number) > 0) { - // Every issue the PR closes is already closed, yet the PR is open: - // the row is live work anchored on the PR. The PR leads (its own - // icon, number and title, full width) and the closed issue is a - // secondary muted chip, so the row never reads as stale - // (hivecommons/hive#14655). A not-planned close adds a chip saying - // the PR may be moot. - const ci = item.closed_issue; - const notPlanned = String(ci.state_reason || '').toLowerCase() === 'not_planned'; - const ciTip = (ci.title || STAGE_TRACKER_CLOSED_ISSUE_TITLE) + ' · closed' + (notPlanned ? ' (not planned)' : '') + ' · PR still open'; - const ak = item.author_kind || 'hive'; - leadHtml = `
- ${stageTrackerIcon('pr', 'ham-kind-ico')}${chip} - ${stageTrackerIcon(ak, 'ham-author-ico ham-author-' + esc(ak), ak + (item.author ? ' · @' + item.author : ''))}#${Number(item.number) || 0} - ${esc(title)} - closes #${Number(ci.number)} · closed${notPlanned ? ' issue closed (not planned)' : ''} -
`; } else { const li = stageTrackerPRIssueSlot(item); prRefs = [stageTrackerPRRef(item.number, item.url, item.author_kind || '', item.author, title, (title ? title + ' · ' : '') + stageTrackerTooltip(shown, nowMs))]; @@ -15749,7 +15735,7 @@

Where to get help

? `
${stageTrackerIcon('issue', 'ham-kind-ico')}${chip} #${li.number} - ${li.title ? `${esc(li.title)}` : `${esc(li.placeholder)}`}${li.soft ? ` refs` : ''}${li.closed ? ' closed' : ''} + ${li.title ? `${esc(li.title)}` : `${esc(li.placeholder)}`}${li.soft ? ` refs` : ''}${li.closed ? ' ' + stageTrackerClosedChipHtml(item, li) : ''}
` : `
${stageTrackerIcon('issue', 'ham-kind-ico')}${chip} @@ -16352,10 +16338,45 @@

Where to get help

const title = li.title || ''; const slot = { number: Number(li.number), title: title, url: li.url || '', closed: closed, placeholder: !title && closed ? STAGE_TRACKER_CLOSED_ISSUE_TITLE : (!title ? STAGE_TRACKER_UNTITLED_ISSUE : '') }; if (soft(li)) slot.soft = true; + if (closed) { + // closed_issue is the same link after the server's closed-by pass; + // prefer its closer / state reason when it names this issue. + const ci = item.closed_issue && Number(item.closed_issue.number) === slot.number ? item.closed_issue : li; + const by = Number(ci.closed_by || li.closed_by) || 0; + if (by > 0) slot.closed_by = by; + const reason = String(ci.state_reason || li.state_reason || '').toLowerCase(); + if (reason) slot.state_reason = reason; + } return slot; } return { number: 0, text: 'no linked issue' }; } + // Pure: the chip(s) beside a closed issue in a PR row's issue slot. + // `closed` when nothing more is known; `closed by #N` linking to the + // merged PR that closed it (the server's merged ledger) when another PR + // delivered the issue — the open PR on this row is then a duplicate + // (hivecommons/hive#15232). A not-planned close adds an "issue closed + // (not planned)" chip: the PR may be moot (hivecommons/hive#14655). + function stageTrackerClosedChipHtml(item, slot) { + const notPlanned = String(slot.state_reason || '') === 'not_planned'; + const by = Number(slot.closed_by) || 0; + let chip; + if (by > 0 && by !== Number(item.number)) { + const url = stageTrackerItemURL(item.repo, by, 'pull', item.url); + chip = `closed by #${by}`; + } else { + chip = 'closed'; + } + return chip + (notPlanned ? ' issue closed (not planned)' : ''); + } + // Pure: the GitHub URL of #number in repo, derived from a sibling item's + // URL when one is at hand (same host, same owner/repo), else from the + // repo name on github.com. + function stageTrackerItemURL(repo, number, kind, siblingURL) { + const m = /^(https?:\/\/[^/]+\/[^/]+\/[^/]+)\/(?:pull|issues)\/\d+/.exec(String(siblingURL || '')); + const base = m ? m[1] : 'https://github.com/' + String(repo || ''); + return base + '/' + (kind === 'pull' ? 'pull' : 'issues') + '/' + (Number(number) || 0); + } function stageTrackerNeedsAttention(item) { const mods = Array.isArray(item.modifiers) ? item.modifiers : [];