Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/fixed-tracker-row-closed-issue.md
Original file line number Diff line number Diff line change
@@ -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).
20 changes: 20 additions & 0 deletions src/pkg/dashboard/merged_ledger.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
61 changes: 52 additions & 9 deletions src/pkg/dashboard/stage_tracker.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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"`
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
}
}
}
119 changes: 119 additions & 0 deletions src/pkg/dashboard/stage_tracker_closed_by_test.go
Original file line number Diff line number Diff line change
@@ -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)
}
}
4 changes: 4 additions & 0 deletions src/pkg/dashboard/stage_tracker_motion_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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' }];
Expand Down Expand Up @@ -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"),
Expand Down
2 changes: 2 additions & 0 deletions src/pkg/dashboard/stage_tracker_repo_grouping_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down
28 changes: 28 additions & 0 deletions src/pkg/dashboard/stage_tracker_ui_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down Expand Up @@ -629,6 +631,32 @@ assert.ok(!row.includes('ham-no-issue-t') && !/<a class="ham-ref"[^>]*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('<span class="ham-title ham-no-issue-t">(closed issue)</span> <span class="ham-badge ham-issue-closed-chip">closed</span>'), 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(/<div class="ham-head-main ham-issue-closed">/.test(row) && /<a class="ham-ref" href="https:\/\/x\/acme\/console\/issues\/15173"[^>]*>#15173<\/a>/.test(row), 'struck-through issue link in the slot: ' + row);
assert.ok(/<a class="ham-badge ham-issue-closed-chip ham-closed-by-chip" href="https:\/\/x\/acme\/console\/pull\/15181"[^>]*>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 <s>'), '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('<span class="ham-badge ham-issue-closed-chip">closed</span> <span class="ham-badge ham-issue-closed-chip ham-closed-not-planned"'), row);
// A closer equal to the row's own PR is not a duplicate: plain chip.
assert.strictEqual(stageTrackerClosedChipHtml({ repo: 'acme/console', number: 500 }, { number: 496, closed_by: 500, title: 'T' }), '<span class="ham-badge ham-issue-closed-chip">closed</span>');
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));
Expand Down
Loading
Loading