diff --git a/apps/web/src/components/chat/ThreadDetailsPrRow.tsx b/apps/web/src/components/chat/ThreadDetailsPrRow.tsx index b916b73f02..98d0fafe3d 100644 --- a/apps/web/src/components/chat/ThreadDetailsPrRow.tsx +++ b/apps/web/src/components/chat/ThreadDetailsPrRow.tsx @@ -3,17 +3,19 @@ * thing worth doing to it right now. * * The row itself opens the pull request in the right panel, exactly as it always has. Around - * that, the host's richer answer — draft, mergeable, conflicting — turns into at most one - * trailing action ("Ready" on a clean draft, "Merge" on a mergeable branch) and a conflict line - * below when the branch cannot merge. All of it runs through the same hooks as the detail panel, - * so the row can never offer something the panel would refuse. + * that, the host's richer answer collapses into a single trailing slot, ranked by what unblocks + * the merge next: "Resolve" on conflicts, "Ready" on a draft, "Fix" under failing checks, and + * "Merge" only once the branch is clean and its checks pass. While checks run the slot reports + * that instead — a merge offered mid-run would race the very runs that gate it. Everything else + * the host knows (title, state, checks tally, diff size) lives in the row's tooltip, so a hover + * answers what previously took opening the panel. * * Until the detail arrives — or where pull requests are not supported at all — the row renders * from the `vcs.status` summary alone, which is the plain row this panel showed before. */ import type { EnvironmentProject } from "@t3tools/client-runtime/state/shell"; import type { EnvironmentId, ProjectId, PullRequestRef } from "@t3tools/contracts"; -import { ArrowUpRightIcon, TriangleAlertIcon } from "lucide-react"; +import { ArrowUpRightIcon, FileDiffIcon, GitBranchIcon, TriangleAlertIcon } from "lucide-react"; import { useState, type MouseEvent as ReactMouseEvent } from "react"; import { cn } from "~/lib/utils"; @@ -22,13 +24,20 @@ import { pullRequestEnvironment } from "~/state/pullRequests"; import { useEnvironmentQuery } from "~/state/query"; import { - allowedPullRequestMergeMethods, + buildFixFindingsHandoff, buildResolveConflictsPrompt, + classifyPullRequestChecks, + describePullRequestChecks, isPullRequestConflicting, - resolvePullRequestPrimaryAction, resolveSelectedMergeMethod, + allowedPullRequestMergeMethods, + resolveThreadPanelPullRequestAction, } from "../pullRequest/pullRequestDetail.logic"; -import { resolvePullRequestState } from "../pullRequest/pullRequestPresentation"; +import { + PullRequestCheckStatusIcon, + PullRequestDiffStat, + resolvePullRequestState, +} from "../pullRequest/pullRequestPresentation"; import { usePullRequestActionRunner, usePullRequestHandoffs, @@ -107,8 +116,10 @@ export function ThreadDetailsPrRow({ const { handoff, startHandoff } = usePullRequestHandoffs({ environmentId, detail }); const [confirmingMerge, setConfirmingMerge] = useState(false); - const primaryAction = resolvePullRequestPrimaryAction(detail); + const rowAction = resolveThreadPanelPullRequestAction(detail); const conflicting = isPullRequestConflicting(detail); + const checksState = detail === null ? "none" : classifyPullRequestChecks(detail.checks); + const checksRunning = detail?.state === "open" && rowAction === null && checksState === "pending"; const selectedMergeMethod = resolveSelectedMergeMethod( allowedPullRequestMergeMethods(detail), "merge", @@ -126,11 +137,37 @@ export function ThreadDetailsPrRow({ }); }; - // Once the host has answered, the glyph knows about drafts, which the vcs summary does not. + const startFixChecks = () => { + if (detail === null) return; + // The compact row fetches no conversation, so the handoff carries the failing checks alone; + // review threads keep arriving through the full panel's richer version of this action. + void startHandoff( + "findings", + buildFixFindingsHandoff({ + number: detail.number, + title: detail.title, + url: detail.url, + headBranch: detail.headBranch, + baseBranch: detail.baseBranch, + reviewThreads: [], + comments: [], + checks: detail.checks, + commentsTruncated: false, + }), + ); + }; + + // Once the host has answered, the glyph knows about drafts and conflicts, which the vcs + // summary does not. Draft outranks conflicts in it, same as the detail panel. const statePresentation = detail === null ? null - : resolvePullRequestState({ state: detail.state, isDraft: detail.isDraft }); + : resolvePullRequestState({ + state: detail.state, + isDraft: detail.isDraft, + mergeability: detail.mergeability, + baseBranch: detail.baseBranch, + }); const icon = statePresentation ? ( ); + // Everything the host reported, at a glance. The row stays one line; the tooltip is where the + // rest of the answer lives — styled like the sidebar's thread tooltip, title above icon-led + // detail rows, so the two read as one family. + const rowTooltip = + detail === null || statePresentation === null ? ( + {status.tooltip} + ) : ( + +
+
+ {detail.title} + #{detail.number} +
+
+
+ +
{statePresentation.label}
+
+
+ +
+ {detail.baseBranch} ← {detail.headBranch} +
+
+ {detail.state === "open" && checksState !== "none" ? ( +
+ +
+ {describePullRequestChecks(detail.checks)} +
+
+ ) : null} + {detail.isDraft && conflicting ? ( +
+ +
+ Merge conflicts with {detail.baseBranch} +
+
+ ) : null} +
+ +
+ {detail.changedFiles.toLocaleString()}{" "} + {detail.changedFiles === 1 ? "file" : "files"} + +
+
+
+
+
+ ); + const trailingAction = - primaryAction === "ready" + rowAction === "resolve" ? { - label: "Ready", - pendingLabel: "Marking...", - tooltip: "Mark this pull request as ready for review", - onClick: () => void perform("ready"), + label: "Resolve", + pendingLabel: "Preparing...", + pending: handoff === "conflicts", + destructive: true, + suffix: , + tooltip: "Check the branch out and resolve the conflicts in a new thread", + onClick: startResolveConflicts, } - : primaryAction === "merge" + : rowAction === "ready" ? { - label: "Merge", - pendingLabel: "Merging...", - tooltip: `Merge this pull request (${selectedMergeMethod})`, - onClick: () => setConfirmingMerge(true), + label: "Ready", + pendingLabel: "Marking...", + pending: actionPending, + destructive: false, + suffix: null, + tooltip: "Mark this pull request as ready for review", + onClick: () => void perform("ready"), } - : null; + : rowAction === "fix" + ? { + label: "Fix", + pendingLabel: "Preparing...", + pending: handoff === "findings", + destructive: true, + suffix: , + tooltip: "Fix the failing checks in a new thread", + onClick: startFixChecks, + } + : rowAction === "merge" + ? { + label: "Merge", + pendingLabel: "Merging...", + pending: actionPending, + destructive: false, + suffix: null, + tooltip: `Merge this pull request (${selectedMergeMethod})`, + onClick: () => setConfirmingMerge(true), + } + : null; const rowContent = ( <> @@ -166,7 +299,7 @@ export function ThreadDetailsPrRow({ return ( <> - {trailingAction ? ( + {trailingAction || checksRunning ? (
{rowContent} - {status.tooltip} + {rowTooltip}
) : ( @@ -220,38 +380,10 @@ export function ThreadDetailsPrRow({ > {rowContent} - {status.tooltip} + {rowTooltip} )} - {conflicting ? ( - // The same words the detail panel says, one click away, so the two read as one thing. -
- - - Merge conflicts - - - - } - > - {handoff === "conflicts" ? "Preparing..." : "Resolve"} - - - - Check the branch out and resolve the conflicts in a new thread - - -
- ) : null} - {primaryAction === "merge" ? ( + {rowAction === "merge" ? ( setConfirmingMerge(open)}> diff --git a/apps/web/src/components/pullRequest/pullRequestDetail.logic.test.ts b/apps/web/src/components/pullRequest/pullRequestDetail.logic.test.ts index faab9d847b..3b4f0e0bbc 100644 --- a/apps/web/src/components/pullRequest/pullRequestDetail.logic.test.ts +++ b/apps/web/src/components/pullRequest/pullRequestDetail.logic.test.ts @@ -9,6 +9,9 @@ import { describe, expect, it } from "vite-plus/test"; import { buildAskAboutLinesHandoff, + classifyPullRequestChecks, + describePullRequestChecks, + resolveThreadPanelPullRequestAction, buildAskAboutPullRequestHandoff, buildExplainPullRequestHandoff, buildFixFindingHandoff, @@ -944,3 +947,98 @@ describe("which actions need the host read again after they run", () => { } }); }); + +describe("the compact row's single action slot", () => { + const check = (status: PullRequestCheck["status"]): PullRequestCheck => ({ + name: "ci", + status, + description: null, + url: null, + }); + const openDetail = ( + overrides: Partial[0] & object> = {}, + ) => + ({ + state: "open", + isDraft: false, + mergeability: "mergeable", + capabilities: { + actions: ["merge", "ready", "draft", "close", "reopen"], + mergeMethods: ["merge", "squash"], + } as unknown as PullRequestDetailView["capabilities"], + viewerPermissions: { + actions: ["merge", "ready", "draft", "close", "reopen"], + } as unknown as PullRequestDetailView["viewerPermissions"], + mergeCapabilities: { merge: true, squash: true, rebase: false }, + checks: [check("success")], + ...overrides, + }) as NonNullable[0]>; + + it("offers Merge only for a clean pull request whose checks pass", () => { + expect(resolveThreadPanelPullRequestAction(openDetail())).toBe("merge"); + expect(resolveThreadPanelPullRequestAction(openDetail({ checks: [] }))).toBe("merge"); + }); + + it("holds the slot while checks run rather than offering a merge that races them", () => { + expect( + resolveThreadPanelPullRequestAction( + openDetail({ checks: [check("success"), check("pending")] }), + ), + ).toBeNull(); + }); + + it("ranks conflicts above everything, then draft, then failing checks", () => { + expect( + resolveThreadPanelPullRequestAction( + openDetail({ mergeability: "conflicting", isDraft: true, checks: [check("failure")] }), + ), + ).toBe("resolve"); + expect( + resolveThreadPanelPullRequestAction( + openDetail({ isDraft: true, checks: [check("failure")] }), + ), + ).toBe("ready"); + expect( + resolveThreadPanelPullRequestAction( + openDetail({ checks: [check("failure"), check("pending")] }), + ), + ).toBe("fix"); + }); + + it("offers nothing the viewer may not do, and nothing on settled pull requests", () => { + expect( + resolveThreadPanelPullRequestAction( + openDetail({ + viewerPermissions: { + actions: [], + } as unknown as PullRequestDetailView["viewerPermissions"], + }), + ), + ).toBeNull(); + expect(resolveThreadPanelPullRequestAction(openDetail({ state: "merged" }))).toBeNull(); + expect(resolveThreadPanelPullRequestAction(null)).toBeNull(); + }); + + it("describes every live facet of the checks at once", () => { + expect(describePullRequestChecks([])).toBe("No checks reported"); + expect(describePullRequestChecks([check("success"), check("success")])).toBe( + "All checks passed", + ); + expect(describePullRequestChecks([check("success"), check("skipped")])).toBe("1 of 2 passing"); + expect( + describePullRequestChecks([ + ...Array.from({ length: 7 }, () => check("pending")), + ...Array.from({ length: 8 }, () => check("success")), + check("failure"), + ]), + ).toBe("7 of 16 running · 1 failed"); + expect(describePullRequestChecks([check("failure"), check("success")])).toBe("1 of 2 failing"); + }); + + it("reads the checks as one word, failing outranking running", () => { + expect(classifyPullRequestChecks([])).toBe("none"); + expect(classifyPullRequestChecks([check("success"), check("skipped")])).toBe("passing"); + expect(classifyPullRequestChecks([check("success"), check("pending")])).toBe("pending"); + expect(classifyPullRequestChecks([check("pending"), check("cancelled")])).toBe("failing"); + }); +}); diff --git a/apps/web/src/components/pullRequest/pullRequestDetail.logic.ts b/apps/web/src/components/pullRequest/pullRequestDetail.logic.ts index 0b57390dcb..8f26406401 100644 --- a/apps/web/src/components/pullRequest/pullRequestDetail.logic.ts +++ b/apps/web/src/components/pullRequest/pullRequestDetail.logic.ts @@ -137,6 +137,68 @@ export function resolvePullRequestPrimaryAction( return allowedPullRequestMergeMethods(detail).length > 0 ? "merge" : null; } +/** The checks as one word. Failing outranks running: a red run is already worth acting on. */ +export type PullRequestChecksState = "none" | "pending" | "failing" | "passing"; + +export function classifyPullRequestChecks( + checks: ReadonlyArray, +): PullRequestChecksState { + if (checks.length === 0) return "none"; + if (checks.some((check) => check.status === "failure" || check.status === "cancelled")) { + return "failing"; + } + if (checks.some((check) => check.status === "pending")) return "pending"; + return "passing"; +} + +/** + * The checks with every live facet, unlike the single-facet summary: a run with failures in it + * still says how much is in flight — "7 of 16 running · 1 failed" — because both numbers change + * what a reader does next. + */ +export function describePullRequestChecks(checks: ReadonlyArray): string { + if (checks.length === 0) return "No checks reported"; + const failed = checks.filter( + (check) => check.status === "failure" || check.status === "cancelled", + ).length; + const pending = checks.filter((check) => check.status === "pending").length; + const passed = checks.filter((check) => check.status === "success").length; + const parts: string[] = []; + if (pending > 0) parts.push(`${pending} of ${checks.length} running`); + if (failed > 0) { + parts.push(pending > 0 ? `${failed} failed` : `${failed} of ${checks.length} failing`); + } + if (parts.length === 0) { + return passed === checks.length ? "All checks passed" : `${passed} of ${checks.length} passing`; + } + return parts.join(" · "); +} + +export type ThreadPanelPullRequestAction = "resolve" | "ready" | "fix" | "merge"; + +/** + * Which single action the thread panel's compact pull request row offers, ranked by what + * unblocks the merge next: conflicts stop everything, a draft is not up for review yet, failing + * checks want fixing, and only a clean open pull request earns Merge. While checks run the slot + * stays empty — the row shows their progress instead of an action that would race them. + */ +export function resolveThreadPanelPullRequestAction( + detail: (PullRequestActionableDetail & Pick) | null, +): ThreadPanelPullRequestAction | null { + if (detail === null || detail.state !== "open") return null; + if (isPullRequestConflicting(detail)) return "resolve"; + if (detail.isDraft) { + return canPerformPullRequestAction(detail, "ready") ? "ready" : null; + } + const checks = classifyPullRequestChecks(detail.checks); + if (checks === "failing") return "fix"; + if (checks === "pending") return null; + return canPerformPullRequestAction(detail, "merge") && + allowedPullRequestMergeMethods(detail).length > 0 + ? "merge" + : null; +} + /** Chronological ascending, oldest to newest — reversed for the "newest" reading order. */ export function orderPullRequestComments( comments: ReadonlyArray,