Skip to content

Commit ac21449

Browse files
feat(pull-requests): quick actions follow each host's capabilities, not GitHub
The shift-held quick actions and the close sweep on the pull requests page, and the quick actions on a thread's linked pull requests, were offered on GitHub only. Nothing behind them is GitHub-only: they run the ordinary `runAction` with close, merge, ready and reopen, which every host declares in `capabilities.actions`. Host summaries in the pull request list now carry those actions, so a row offers what its host can do before its detail is read. A thread's linked pull requests read them from the host's client definition, which is now where each server provider takes its action list from too, so the two can't disagree. Servers that report no actions keep the old GitHub-only behavior. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent cd33ae9 commit ac21449

24 files changed

Lines changed: 254 additions & 83 deletions

File tree

‎apps/server/src/pullRequest/PullRequestService.test.ts‎

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -572,6 +572,35 @@ it.effect("lists GitHub Enterprise PRs for a stored unknown repository after hos
572572
}),
573573
);
574574

575+
it.effect("reports each host's actions with its summary, so rows can offer them unread", () =>
576+
Effect.gen(function* () {
577+
const service = yield* makeService({
578+
projects: [
579+
project({
580+
id: "p1",
581+
title: "web",
582+
workspaceRoot: "/repo",
583+
repository: "acme/web",
584+
provider: SourceControlProviderKind.make("bitbucket"),
585+
host: "bitbucket.org",
586+
}),
587+
],
588+
providers: [
589+
fakeProvider(SourceControlProviderKind.make("bitbucket"), {
590+
capabilities: {
591+
...fakeProvider(SourceControlProviderKind.make("bitbucket")).capabilities,
592+
actions: ["merge", "close"],
593+
},
594+
}),
595+
],
596+
});
597+
598+
const result = yield* service.list({ state: "open" });
599+
600+
assert.deepStrictEqual(result.providers[0]?.actions, ["merge", "close"]);
601+
}),
602+
);
603+
575604
it.effect("refines unknown self-hosted GitLab projects before listing merge requests", () =>
576605
Effect.gen(function* () {
577606
let refinementCalls = 0;

‎apps/server/src/pullRequest/PullRequestService.ts‎

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1252,20 +1252,24 @@ export const make = Effect.gen(function* () {
12521252
// One summary per host, which is what the viewer lookup already answers for: two GitHub
12531253
// hosts sign in separately, so collapsing them by kind would report one as the other.
12541254
const providers: ReadonlyArray<PullRequestProviderSummary> = [
1255-
...viewerResults.map((result) => ({
1256-
host: result.host,
1257-
kind: result.kind,
1258-
searchesOnHost:
1259-
projects.find((project) => project.host === result.host)?.api.capabilities.search ??
1260-
false,
1261-
projectCount: projectCounts.get(result.host) ?? 1,
1262-
configured: result.viewer !== null,
1263-
detail: result.error === null ? null : providerDetail(result.error),
1264-
})),
1255+
...viewerResults.map((result) => {
1256+
const capabilities = projects.find((project) => project.host === result.host)?.api
1257+
.capabilities;
1258+
return {
1259+
host: result.host,
1260+
kind: result.kind,
1261+
searchesOnHost: capabilities?.search ?? false,
1262+
actions: capabilities?.actions ?? [],
1263+
projectCount: projectCounts.get(result.host) ?? 1,
1264+
configured: result.viewer !== null,
1265+
detail: result.error === null ? null : providerDetail(result.error),
1266+
};
1267+
}),
12651268
...[...unimplemented].map(([host, { kind, projectCount }]) => ({
12661269
host,
12671270
kind,
12681271
searchesOnHost: false,
1272+
actions: [],
12691273
projectCount,
12701274
configured: false,
12711275
detail: "This host cannot be browsed here yet.",

‎apps/web/src/components/pullRequest/PullRequestRow.tsx‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import type { PullRequestAction } from "@t3tools/contracts";
12
import { sourceControlClients } from "@t3tools/client-runtime/source-control-clients";
23
import { SearchIcon } from "lucide-react";
34
import { PullRequestStackPopover } from "./PullRequestStackPopover";
@@ -91,6 +92,7 @@ function PullRequestRowImpl({
9192
statsRef,
9293
onSelect,
9394
speedMode,
95+
hostActions,
9496
onActed,
9597
closing = false,
9698
sweeping = false,
@@ -113,6 +115,8 @@ function PullRequestRowImpl({
113115
statsRef?: RefCallback<HTMLDivElement>;
114116
onSelect: (entry: PullRequestRowTarget) => void;
115117
speedMode: boolean;
118+
/** What this row's host can do, which is what speed mode offers. */
119+
hostActions: ReadonlySet<PullRequestAction>;
116120
onActed: (result: PullRequestSpeedActionResult) => void;
117121
closing?: boolean;
118122
sweeping?: boolean;
@@ -256,9 +260,10 @@ function PullRequestRowImpl({
256260
updatedAt={entry.updatedAt}
257261
/>
258262
</button>
259-
{entry.state !== "merged" && entry.provider === "github" ? (
263+
{hostActions.size > 0 ? (
260264
<PullRequestSpeedActions
261265
entry={entry}
266+
hostActions={hostActions}
262267
visible={speedMode}
263268
onActed={onActed}
264269
closing={closing}

‎apps/web/src/components/pullRequest/PullRequestSpeedActions.tsx‎

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { Spinner } from "../ui/spinner";
77
import { Tooltip, TooltipPopup, TooltipTrigger } from "../ui/tooltip";
88
import { resolvePullRequestMergeMethod } from "./pullRequestDetail.logic";
99
import { PullRequestGlyph } from "./pullRequestIcons";
10-
import type { EnvironmentPullRequestEntry } from "./pullRequestList.logic";
10+
import { pullRequestQuickActions, type EnvironmentPullRequestEntry } from "./pullRequestList.logic";
1111
import {
1212
usePullRequestActionRunner,
1313
usePullRequestDefaultMergeMethodResolver,
@@ -26,13 +26,16 @@ export interface PullRequestSpeedActionResult<Entry = EnvironmentPullRequestEntr
2626
/** No detail or stack reads until a merge is clicked, even on a long list. */
2727
export function PullRequestSpeedActions<Entry extends PullRequestSpeedActionEntry>({
2828
entry,
29+
hostActions,
2930
visible,
3031
onActed,
3132
closing = false,
3233
sweeping = false,
3334
onCloseSweepStart,
3435
}: {
3536
entry: Entry;
37+
/** What the row's host can do; actions it cannot are not offered. */
38+
hostActions: ReadonlySet<PullRequestAction>;
3639
visible: boolean;
3740
onActed?: (result: PullRequestSpeedActionResult<Entry>) => void;
3841
closing?: boolean;
@@ -70,13 +73,9 @@ export function PullRequestSpeedActions<Entry extends PullRequestSpeedActionEntr
7073
);
7174
},
7275
});
73-
const actions =
74-
entry.state === "closed"
75-
? (["reopen"] as const)
76-
: entry.isDraft
77-
? (["close", "ready"] as const)
78-
: (["close", "merge"] as const);
76+
const actions = pullRequestQuickActions(entry, hostActions);
7977
const busy = actionPending || closing || sweeping;
78+
if (actions.length === 0) return null;
8079
return (
8180
<div
8281
className="shrink-0 items-center gap-1 pr-3"

‎apps/web/src/components/pullRequest/ThreadPullRequestsPanel.tsx‎

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import type { ProjectId, ScopedThreadRef, ThreadPullRequestLink } from "@t3tools/contracts";
2-
import { detectSourceControlProviderFromRemoteUrl } from "@t3tools/shared/sourceControl";
3-
import { sourceControlClients } from "@t3tools/client-runtime/source-control-clients";
2+
import {
3+
sourceControlClients,
4+
UNKNOWN_SOURCE_CONTROL_CLIENT,
5+
} from "@t3tools/client-runtime/source-control-clients";
46
import {
57
resolveThreadPullRequestChains,
68
visibleThreadPullRequests,
@@ -45,6 +47,7 @@ import {
4547
pullRequestChecksStatePresentation,
4648
} from "./pullRequestPresentation";
4749
import { PullRequestGlyph } from "./pullRequestIcons";
50+
import { pullRequestQuickActions } from "./pullRequestList.logic";
4851
import { PullRequestSpeedActions } from "./PullRequestSpeedActions";
4952

5053
const SOURCE_LABELS: Record<ThreadPullRequestLink["source"], string> = {
@@ -105,11 +108,12 @@ function LinkRow({
105108
const snapshot = link.snapshot;
106109
const open = snapshot === null || snapshot.state === "open";
107110
const watching = link.watch !== undefined;
111+
// A link carries no host summary, so the host's own definition says what it can do.
112+
const linkHostActions = (
113+
sourceControlClients.findByChangeRequestUrl(link.url) ?? UNKNOWN_SOURCE_CONTROL_CLIENT
114+
).changeRequestActions;
108115
const actionEntry =
109-
projectId !== null &&
110-
snapshot !== null &&
111-
snapshot.state !== "merged" &&
112-
detectSourceControlProviderFromRemoteUrl(link.url)?.kind === "github"
116+
projectId !== null && snapshot !== null && snapshot.state !== "merged"
113117
? {
114118
environmentId: threadRef.environmentId,
115119
projectId,
@@ -121,6 +125,9 @@ function LinkRow({
121125
...(link.stack === null ? {} : { stack: link.stack }),
122126
}
123127
: null;
128+
// Speed mode swaps the menu for quick actions only where a row has some to offer.
129+
const hasQuickActions =
130+
actionEntry !== null && pullRequestQuickActions(actionEntry, linkHostActions).length > 0;
124131
return (
125132
<div
126133
className={cn(PULL_REQUEST_ROW_CLASS, "relative hover:bg-accent/60")}
@@ -246,7 +253,11 @@ function LinkRow({
246253
/>
247254
</a>
248255
{actionEntry !== null ? (
249-
<PullRequestSpeedActions entry={actionEntry} visible={speedMode} />
256+
<PullRequestSpeedActions
257+
entry={actionEntry}
258+
hostActions={linkHostActions}
259+
visible={speedMode}
260+
/>
250261
) : null}
251262
{/* Out of the row's flow, so no row reserves a column for a button only the hovered one
252263
shows. It sits over the right end of the second line on the row's own hover color,
@@ -261,7 +272,7 @@ function LinkRow({
261272
"has-[[data-popup-open]]:pointer-events-auto has-[[data-popup-open]]:opacity-100",
262273
"has-[:focus-visible]:pointer-events-auto has-[:focus-visible]:opacity-100",
263274
"group-has-[[data-pull-request-action-pending=true]]/pr-row:hidden",
264-
speedMode && actionEntry !== null && "hidden",
275+
speedMode && hasQuickActions && "hidden",
265276
)}
266277
>
267278
<span aria-hidden className="absolute inset-0 bg-accent/60" />

‎apps/web/src/components/pullRequest/pullRequestChecks.test.tsx‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ function row(overrides: Partial<EnvironmentPullRequestEntry>): ReactNode {
103103
showProvider: false,
104104
onSelect: () => {},
105105
speedMode: false,
106+
hostActions: new Set(),
106107
onActed: () => {},
107108
});
108109
}

‎apps/web/src/components/pullRequest/pullRequestList.logic.test.ts‎

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,15 @@
11
import { SourceControlProviderKind } from "@t3tools/contracts";
2-
import type { EnvironmentId, ProjectId, PullRequestListEntry } from "@t3tools/contracts";
2+
import type {
3+
EnvironmentId,
4+
ProjectId,
5+
PullRequestAction,
6+
PullRequestListEntry,
7+
} from "@t3tools/contracts";
38
import { describe, expect, it } from "vite-plus/test";
49

510
import {
11+
pullRequestHostActions,
12+
pullRequestQuickActions,
613
filterPullRequestsByInvolvement,
714
findScopedProject,
815
mergePullRequestLists,
@@ -1720,3 +1727,35 @@ describe("pull request list override settlement", () => {
17201727
expect(swapped.map((row) => row.number)).toEqual([2, 1]);
17211728
});
17221729
});
1730+
1731+
describe("pull request quick actions", () => {
1732+
const summary = (host: string, kind: string, actions?: ReadonlyArray<PullRequestAction>) => ({
1733+
host,
1734+
kind: SourceControlProviderKind.make(kind),
1735+
searchesOnHost: true,
1736+
projectCount: 1,
1737+
configured: true,
1738+
detail: null,
1739+
...(actions === undefined ? {} : { actions }),
1740+
});
1741+
1742+
it("offers what each host reports, and GitHub's legacy set when a server reports none", () => {
1743+
const actionsOf = pullRequestHostActions([
1744+
summary("bitbucket.org", "bitbucket", ["merge", "close"]),
1745+
summary("github.com", "github"),
1746+
]);
1747+
const bitbucket = actionsOf({
1748+
host: "bitbucket.org",
1749+
provider: SourceControlProviderKind.make("bitbucket"),
1750+
});
1751+
expect(pullRequestQuickActions({ state: "closed", isDraft: false }, bitbucket)).toEqual([]);
1752+
const github = actionsOf({
1753+
host: "github.com",
1754+
provider: SourceControlProviderKind.make("github"),
1755+
});
1756+
expect(pullRequestQuickActions({ state: "open", isDraft: true }, github)).toEqual([
1757+
"close",
1758+
"ready",
1759+
]);
1760+
});
1761+
});

‎apps/web/src/components/pullRequest/pullRequestList.logic.ts‎

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1262,3 +1262,45 @@ export function settlePullRequestOverrides<Entry extends PullRequestListEntry>(
12621262
}
12631263
return kept.size === overrides.size ? overrides : kept;
12641264
}
1265+
1266+
/** The row actions speed mode offers, in the order they are drawn. */
1267+
export type PullRequestQuickAction = "close" | "merge" | "ready" | "reopen";
1268+
1269+
/**
1270+
* Which actions each host can take on a listed row, before any row's detail is read. Hosts are
1271+
* matched by the host summary; a server that does not report actions per host only ever offered
1272+
* these on GitHub, so that is what it keeps getting.
1273+
*/
1274+
export function pullRequestHostActions(
1275+
providers: ReadonlyArray<PullRequestListResult["providers"][number]>,
1276+
): (
1277+
entry: Pick<EnvironmentPullRequestEntry, "host" | "provider">,
1278+
) => ReadonlySet<PullRequestAction> {
1279+
const byHost = new Map(
1280+
providers.flatMap((provider) =>
1281+
provider.actions === undefined
1282+
? []
1283+
: [[provider.host.toLowerCase(), new Set(provider.actions)] as const],
1284+
),
1285+
);
1286+
const legacy = new Set<PullRequestAction>(["close", "merge", "ready", "reopen"]);
1287+
const none = new Set<PullRequestAction>();
1288+
return (entry) =>
1289+
byHost.get(entry.host.toLowerCase()) ?? (entry.provider === "github" ? legacy : none);
1290+
}
1291+
1292+
/** The quick actions a row offers: what its state allows, narrowed to what its host can do. */
1293+
export function pullRequestQuickActions(
1294+
entry: Pick<EnvironmentPullRequestEntry, "state" | "isDraft">,
1295+
hostActions: ReadonlySet<PullRequestAction>,
1296+
): ReadonlyArray<PullRequestQuickAction> {
1297+
const forState: ReadonlyArray<PullRequestQuickAction> =
1298+
entry.state === "merged"
1299+
? []
1300+
: entry.state === "closed"
1301+
? ["reopen"]
1302+
: entry.isDraft
1303+
? ["close", "ready"]
1304+
: ["close", "merge"];
1305+
return forState.filter((action) => hostActions.has(action));
1306+
}

‎apps/web/src/components/pullRequest/usePullRequestActions.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -186,8 +186,8 @@ export function usePullRequestCloseBatch(onClosed: (entry: EnvironmentPullReques
186186
async (entries: readonly EnvironmentPullRequestEntry[]) => {
187187
const batch = entries.filter((entry) => {
188188
const key = pullRequestEntryKey(entry);
189-
if (entry.state !== "open" || entry.provider !== "github" || pending.current.has(key))
190-
return false;
189+
// The sweep only gathers rows whose host can close them, so state is all that is left.
190+
if (entry.state !== "open" || pending.current.has(key)) return false;
191191
pending.current.add(key);
192192
return true;
193193
});

0 commit comments

Comments
 (0)