diff --git a/changelog.d/fixed-tracker-row-anchor-open-pr.md b/changelog.d/fixed-tracker-row-anchor-open-pr.md new file mode 100644 index 0000000000..eef6c273ad --- /dev/null +++ b/changelog.d/fixed-tracker-row-anchor-open-pr.md @@ -0,0 +1 @@ +- Dashboard activity tracker: a pull request whose `Fixes #N` issue has already closed while the PR is still open is now anchored on the PR — the PR's number, title, stage and age lead the row and the closed issue becomes a muted `closes #N · closed` chip (plus `issue closed (not planned)` when GitHub says so) — instead of drawing the dead issue struck through as the headline (hivecommons/hive#14655). diff --git a/src/docs/dashboard-sections.md b/src/docs/dashboard-sections.md index 9a4dd82a90..5a086251a4 100644 --- a/src/docs/dashboard-sections.md +++ b/src/docs/dashboard-sections.md @@ -655,6 +655,8 @@ Fed by `GET /api/stage-tracker`. Every issue and pull request follows the same p **Sentinel alert.** A pull request the suspicious-activity sentinel flagged — it wears the `sentinel-alert` label (`sentinel.label`), or the review evidence bundle for its current head records sentinel findings — carries `sentinel_alert: true` in the tracker payload (with `sentinel_findings` and a short `sentinel_reason` when the bundle has them); a webhook label change flips it live. In the **Needs human decision** lane the lit chevron's own words read **Sentinel alert · needs human** (danger-tinted, the same wording in the cell's `title` and `aria-label`, and in the compact caption), so a maintainer reads the security implication before the stage mechanics; in every other lane the row shows a compact danger-tinted `sentinel` chip ahead of `needs rebase` / `regressed` / `stalled`. The tooltip reads "Sentinel flagged security-relevant changes at ``: ``" (a generic description stands in when the bundle has no reason). An issue carried by one flagged PR shows the lane text too, and a nested PR sub-row shows its own. The *Decide…* dialogs for a flagged PR open with a ⚠ line per flagged PR naming the sentinel reason, and *Approve* is styled as a dangerous action. Lane text and chip update in place on refresh (keyed reconcile, no flash). **Unauthorized pill.** A pull request the hive cannot move because its GitHub App lacks a permission for the next step — it wears `hive:unauthorized` ([#14589](https://github.com/hivecommons/hive/issues/14589)); first case: approving held `action_required` workflow runs needs `actions: write` — carries the `unauthorized` modifier in the tracker payload, drawn in the far-right pill column exactly like `stalled` / `hold` / `draft` but muted (dashed, `--text-muted`), never red: it is nothing wrong, just a step only a person may take. It counts under **Needs attention**. Its tooltip (payload `unauthorized`) names the missing permission and the human step; on the **Needs human decision** lane the lit chevron and the caption read **Awaiting human: approve workflow runs** (payload `unauthorized_step`, from the `unauthorized:` stage reason). The pill, label and payload fields clear themselves in the tick the step is no longer needed. +**Closed issue, open PR.** A pull request whose `Fixes #N` issue has already closed (auto-closed by a bot, or closed by hand) while the PR is still open is live work, not a stale line: the row is anchored on the PR ([#14655](https://github.com/hivecommons/hive/issues/14655)). The PR's own icon, number and title lead the row at full width, its stage drives the strip and its timestamps sort it — closing the issue is not a regression of the PR — and the closed issue shrinks to a muted `closes #N · closed` chip linking to it. An issue closed as *not planned* adds an `issue closed (not planned)` chip so the reader can tell the PR may be moot. At 090 such a row still counts under *Needs attention*: the human has a merge to click. When the PR closes or merges too, the row leaves the list as before (a merged PR shows in *Recently merged* for its retention window). + **Row gutter.** Every issue and PR row (never a column or repo-group header) carries a left gutter with a select checkbox and a ⋯ actions button that is always present and always visible: dimmed at rest (`--ham-tool-rest-opacity`), at full emphasis on the row under the pointer or holding focus, on a selected row, and on every row while anything is selected or the context menu is open — the only animation is the hover fade (`--ham-tool-fade-ms`, ≤ 120 ms), and nothing about it depends on scrolling, row position or which rows the live refresh re-created. diff --git a/src/pkg/dashboard/stage_tracker.go b/src/pkg/dashboard/stage_tracker.go index b82ef6cfc0..9a4448dc59 100644 --- a/src/pkg/dashboard/stage_tracker.go +++ b/src/pkg/dashboard/stage_tracker.go @@ -334,7 +334,14 @@ type StageTrackerItem struct { // works towards an issue joins its row instead of standing as an // orphan (hivecommons/hive#13544). LinkedIssues []StageTrackerLinkedIssue `json:"linked_issues,omitempty"` - History []StageTrackerHop `json:"history"` + // 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). + ClosedIssue *StageTrackerLinkedIssue `json:"closed_issue,omitempty"` + History []StageTrackerHop `json:"history"` } // StageTrackerLinkedIssue is one issue a PR closes, as its row's issue @@ -344,6 +351,9 @@ type StageTrackerLinkedIssue struct { Title string `json:"title,omitempty"` URL string `json:"url,omitempty"` State string `json:"state,omitempty"` + // StateReason is GitHub's stateReason for a closed issue, lower-cased + // ("completed", "not_planned", "duplicate"); "" when unknown. + StateReason string `json:"state_reason,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"` @@ -1549,7 +1559,8 @@ func stageTrackerPRLinkedIssues(pr github.PullRequest, repoName, baseURL string) seen[li.Number] = true out = append(out, StageTrackerLinkedIssue{ Number: li.Number, Title: li.Title, State: strings.ToLower(strings.TrimSpace(li.State)), - URL: overviewItemURL(li.URL, full, li.Number, "issue", baseURL), Via: via, + StateReason: strings.ToLower(strings.TrimSpace(li.StateReason)), + URL: overviewItemURL(li.URL, full, li.Number, "issue", baseURL), Via: via, }) } for _, li := range pr.LinkedIssues { @@ -1709,4 +1720,45 @@ func stageTrackerResolveLinkedPRs(items []StageTrackerItem) { } it.LinkedPRs = out } + for i := range items { + if items[i].Kind == "pr" { + items[i].ClosedIssue = stageTrackerClosedIssueAnchor(items[i]) + } + } +} + +// stageTrackerClosedIssueAnchor returns the closed issue a standalone PR +// 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. +func stageTrackerClosedIssueAnchor(pr StageTrackerItem) *StageTrackerLinkedIssue { + if pr.Kind != "pr" || pr.NestedUnder != 0 { + return nil + } + var closed *StageTrackerLinkedIssue + for i := range pr.LinkedIssues { + li := &pr.LinkedIssues[i] + if li.Listed || stageTrackerLinkSoft(*li) { + continue + } + switch li.State { + case "closed": + if closed == nil { + closed = li + } + default: + // An open (or unknown-state) closing link still anchors the row + // on the issue. + return nil + } + } + if closed == nil { + return nil + } + out := *closed + return &out } diff --git a/src/pkg/dashboard/stage_tracker_test.go b/src/pkg/dashboard/stage_tracker_test.go index 15325b098c..7a0adc80ee 100644 --- a/src/pkg/dashboard/stage_tracker_test.go +++ b/src/pkg/dashboard/stage_tracker_test.go @@ -827,3 +827,106 @@ func TestStageTrackerStaleDecisionRecord(t *testing.T) { } } } + +// TestStageTrackerRowAnchorsOnOpenPRWhenIssueClosed pins +// hivecommons/hive#14655: an issue auto-closed while its `Fixes #N` PR is +// still open at 090 stays in the tracker as a row keyed on the PR — the +// PR's stage, no regression modifier, the closed issue demoted to the +// closed_issue chip (with its not-planned state_reason when GitHub says +// so). With the PR gone too, nothing remains. +func TestStageTrackerRowAnchorsOnOpenPRWhenIssueClosed(t *testing.T) { + now := time.Date(2026, 10, 27, 18, 15, 0, 0, time.UTC) + const issueNum, prNum = 14567, 14568 + tests := []struct { + name string + stateReason string + prOpen bool + wantRow bool + }{ + {name: "issue completed, PR open", stateReason: "completed", prOpen: true, wantRow: true}, + {name: "issue not planned, PR open", stateReason: "not_planned", prOpen: true, wantRow: true}, + {name: "issue closed, PR merged", stateReason: "completed", prOpen: false, wantRow: false}, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + s := newTestServer() + clock := now + store := stagelabels.NewStore("", func() time.Time { return clock }) + s.stageStore = store + key := stagelabels.Key("hivecommons/hive", prNum) + clock = now.Add(-3 * time.Hour) + store.Observe(key, stagelabels.ReviewPending, "contributor-lane:no-verdict") + clock = now.Add(-2 * time.Hour) + store.Observe(key, stagelabels.ReadyForHumanMerge, "contributor-lane:workflow-path:human-approved@clubanderson") + clock = now + + status := minimalPayload() + status.HiveID = "hv-test" + repo := FrontendRepo{Name: "hive", Full: "hivecommons/hive", + ActionableIssues: []any{github.Issue{Number: issueNum, Title: "[CI runner canary] self-hosted runner pool unhealthy", Author: "github-actions[bot]", State: "closed", Labels: []string{"stage/040-covered-by-pr"}}}} + if tt.prOpen { + repo.OpenPrs = []any{FrontendPR{PullRequest: github.PullRequest{Number: prNum, Title: "fix(ci): measure runner stalls by queued job age", Author: "hive-app[bot]", AppAuthored: true, + Labels: []string{"stage/090-ready-for-human-merge", "lgtm"}, CreatedAt: now.Add(-4 * time.Hour), UpdatedAt: now.Add(-time.Hour), + LinkedIssues: []github.PRLinkedIssue{{Number: issueNum, Repo: "hivecommons/hive", Title: "[CI runner canary] self-hosted runner pool unhealthy", State: "CLOSED", StateReason: strings.ToUpper(tt.stateReason)}}}}} + } + status.Repos = []FrontendRepo{repo} + s.UpdateStatus(status) + resp := s.buildStageTracker(status, store, now) + + for _, it := range resp.Items { + if it.Kind == "issue" && it.Number == issueNum { + t.Fatalf("closed issue #%d is still a row: %+v", issueNum, it) + } + } + if !tt.wantRow { + if len(resp.Items) != 0 { + t.Fatalf("items = %+v, want none", resp.Items) + } + return + } + if len(resp.Items) != 1 { + t.Fatalf("items = %d, want the PR row only", len(resp.Items)) + } + pr := trackerItem(t, resp, "pr", prNum) + if pr.Stage != trackerNumberReadyForHuman || pr.NestedUnder != 0 || pr.StageSince == nil || !pr.StageSince.Equal(now.Add(-2*time.Hour)) { + t.Fatalf("PR row stage = %d since %v nested %d, want 090 from the PR's own record", pr.Stage, pr.StageSince, pr.NestedUnder) + } + if slices.Contains(pr.Modifiers, modRegressed) || pr.RegressedFrom != 0 { + t.Fatalf("issue closure read as a regression: modifiers %v regressed_from %d", pr.Modifiers, pr.RegressedFrom) + } + if !pr.ManualMerge || pr.HumanApprover != "clubanderson" { + t.Fatalf("merge gate = manual %v approver %q, want the human-merge gate intact", pr.ManualMerge, pr.HumanApprover) + } + if pr.ClosedIssue == nil || pr.ClosedIssue.Number != issueNum || pr.ClosedIssue.State != "closed" || pr.ClosedIssue.StateReason != tt.stateReason || pr.ClosedIssue.Title == "" { + t.Fatalf("closed_issue = %+v, want #%d closed (%s) with its title", pr.ClosedIssue, issueNum, tt.stateReason) + } + }) + } +} + +func TestStageTrackerClosedIssueAnchor(t *testing.T) { + closed := StageTrackerLinkedIssue{Number: 7, State: "closed"} + tests := []struct { + name string + pr StageTrackerItem + want *StageTrackerLinkedIssue + }{ + {name: "not a pr", pr: StageTrackerItem{Kind: "issue", LinkedIssues: []StageTrackerLinkedIssue{closed}}}, + {name: "no links", pr: StageTrackerItem{Kind: "pr"}}, + {name: "nested under a listed issue", pr: StageTrackerItem{Kind: "pr", NestedUnder: 8, LinkedIssues: []StageTrackerLinkedIssue{{Number: 8, State: "open", Listed: true}, closed}}}, + {name: "one closing link still open", pr: StageTrackerItem{Kind: "pr", LinkedIssues: []StageTrackerLinkedIssue{closed, {Number: 9, State: "open"}}}}, + {name: "unknown state keeps the issue slot", pr: StageTrackerItem{Kind: "pr", LinkedIssues: []StageTrackerLinkedIssue{{Number: 9}}}}, + {name: "soft links only", pr: StageTrackerItem{Kind: "pr", LinkedIssues: []StageTrackerLinkedIssue{{Number: 9, State: "closed", Via: github.PRLinkViaRefs}}}}, + {name: "closed closing link", pr: StageTrackerItem{Kind: "pr", LinkedIssues: []StageTrackerLinkedIssue{closed}}, want: &closed}, + {name: "closed closing link beside a soft one", pr: StageTrackerItem{Kind: "pr", LinkedIssues: []StageTrackerLinkedIssue{{Number: 9, Via: github.PRLinkViaMention}, closed}}, want: &closed}, + {name: "first closed wins", pr: StageTrackerItem{Kind: "pr", LinkedIssues: []StageTrackerLinkedIssue{closed, {Number: 11, State: "closed", StateReason: "not_planned"}}}, want: &closed}, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + got := stageTrackerClosedIssueAnchor(tt.pr) + if (got == nil) != (tt.want == nil) || (got != nil && *got != *tt.want) { + t.Fatalf("got %+v, want %+v", got, tt.want) + } + }) + } +} diff --git a/src/pkg/dashboard/static/index.html b/src/pkg/dashboard/static/index.html index 34f61d8e8f..f6f9d51a6c 100644 --- a/src/pkg/dashboard/static/index.html +++ b/src/pkg/dashboard/static/index.html @@ -1431,6 +1431,11 @@ .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; } /* 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 @@ -14501,10 +14506,12 @@

Where to get help

} // Invariant (owner): the issue slot on the left never holds a PR. A // PR whose issue is listed is nested under it; a PR seen on its own - // (no issue, a closed 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. + // (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. // The repo chip (when on) leads the row, before the issue slot's #N. const chip = ctx.repoChips ? stageTrackerRepoChipHtml(item.repo, ctx) : ''; let leadHtml; @@ -14516,6 +14523,23 @@

Where to get help

${item.claim_reference ? `refs` : ''} ${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))]; diff --git a/src/pkg/github/client.go b/src/pkg/github/client.go index 57735939b9..ea7f9c15a1 100644 --- a/src/pkg/github/client.go +++ b/src/pkg/github/client.go @@ -1016,13 +1016,16 @@ type PullRequest struct { // PRLinkedIssue is an issue GitHub reports a PR will close on merge // (closingIssuesReferences) — the PR-side mirror of IssueLinkedPR. State is -// GitHub's issue state lower-cased ("open" / "closed"), as on Issue.State. +// GitHub's issue state lower-cased ("open" / "closed"), as on Issue.State; +// StateReason is its stateReason lower-cased ("completed" / "not_planned" / +// "duplicate" / "reopened"), "" when unknown. type PRLinkedIssue struct { - Number int `json:"number"` - Title string `json:"title,omitempty"` - Repo string `json:"repo,omitempty"` - State string `json:"state,omitempty"` - URL string `json:"url,omitempty"` + Number int `json:"number"` + Title string `json:"title,omitempty"` + Repo string `json:"repo,omitempty"` + State string `json:"state,omitempty"` + StateReason string `json:"state_reason,omitempty"` + URL string `json:"url,omitempty"` // Via is how the link was found: "" for GitHub's closing reference, // else one of the PRLinkVia* values (pr_reference_links.go). Via string `json:"via,omitempty"` diff --git a/src/pkg/github/pr_batch_graphql.go b/src/pkg/github/pr_batch_graphql.go index 0b593115cf..fe6275698e 100644 --- a/src/pkg/github/pr_batch_graphql.go +++ b/src/pkg/github/pr_batch_graphql.go @@ -44,7 +44,7 @@ query($owner: String!, $name: String!, $first: Int!, $cursor: String) { } } } - closingIssuesReferences(first: 10) { nodes { number title state url repository { nameWithOwner } } } + closingIssuesReferences(first: 10) { nodes { number title state stateReason url repository { nameWithOwner } } } } } } @@ -108,11 +108,12 @@ type graphQLPRBatchNode struct { } `json:"commits"` ClosingIssuesReferences struct { Nodes []struct { - Number int `json:"number"` - Title string `json:"title"` - State string `json:"state"` - URL string `json:"url"` - Repository struct { + Number int `json:"number"` + Title string `json:"title"` + State string `json:"state"` + StateReason string `json:"stateReason"` + URL string `json:"url"` + Repository struct { NameWithOwner string `json:"nameWithOwner"` } `json:"repository"` } `json:"nodes"` @@ -359,11 +360,12 @@ func (c *Client) storeGraphQLPRBatchReview(repo string, n graphQLPRBatchNode) { for _, li := range n.ClosingIssuesReferences.Nodes { if li.Number > 0 { st.linkedIssues = append(st.linkedIssues, PRLinkedIssue{ - Number: li.Number, - Title: li.Title, - Repo: li.Repository.NameWithOwner, - State: strings.ToLower(strings.TrimSpace(li.State)), - URL: li.URL, + Number: li.Number, + Title: li.Title, + Repo: li.Repository.NameWithOwner, + State: strings.ToLower(strings.TrimSpace(li.State)), + StateReason: strings.ToLower(strings.TrimSpace(li.StateReason)), + URL: li.URL, }) } } diff --git a/src/pkg/github/protection_facts.go b/src/pkg/github/protection_facts.go index a0d8246afc..af9e051172 100644 --- a/src/pkg/github/protection_facts.go +++ b/src/pkg/github/protection_facts.go @@ -230,7 +230,7 @@ const reviewSignalsQuery = `query($owner:String!,$name:String!,$cursor:String){ latestOpinionatedReviews(first:50){nodes{state submittedAt authorAssociation author{__typename login}}} comments(first:1){totalCount} reviewThreads(first:1){totalCount} - closingIssuesReferences(first:20){nodes{number title state url repository{nameWithOwner}}} + closingIssuesReferences(first:20){nodes{number title state stateReason url repository{nameWithOwner}}} } } } @@ -265,11 +265,12 @@ type reviewDecisionResponse struct { } `json:"reviewThreads"` ClosingIssuesReferences struct { Nodes []struct { - Number int `json:"number"` - Title string `json:"title"` - State string `json:"state"` - URL string `json:"url"` - Repository struct { + Number int `json:"number"` + Title string `json:"title"` + State string `json:"state"` + StateReason string `json:"stateReason"` + URL string `json:"url"` + Repository struct { NameWithOwner string `json:"nameWithOwner"` } `json:"repository"` } `json:"nodes"` @@ -333,11 +334,12 @@ func (c *Client) fetchReviewDecisions(ctx context.Context, repo string) map[int] continue } st.linkedIssues = append(st.linkedIssues, PRLinkedIssue{ - Number: li.Number, - Title: li.Title, - Repo: li.Repository.NameWithOwner, - State: strings.ToLower(strings.TrimSpace(li.State)), - URL: li.URL, + Number: li.Number, + Title: li.Title, + Repo: li.Repository.NameWithOwner, + State: strings.ToLower(strings.TrimSpace(li.State)), + StateReason: strings.ToLower(strings.TrimSpace(li.StateReason)), + URL: li.URL, }) } for _, r := range n.LatestOpinionatedReviews.Nodes {