Skip to content

Commit 1ae61da

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 f6baca3 commit 1ae61da

24 files changed

Lines changed: 249 additions & 82 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: 14 additions & 7 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,
@@ -105,11 +107,12 @@ function LinkRow({
105107
const snapshot = link.snapshot;
106108
const open = snapshot === null || snapshot.state === "open";
107109
const watching = link.watch !== undefined;
110+
// A link carries no host summary, so the host's own definition says what it can do.
111+
const linkHostActions = (
112+
sourceControlClients.findByChangeRequestUrl(link.url) ?? UNKNOWN_SOURCE_CONTROL_CLIENT
113+
).changeRequestActions;
108114
const actionEntry =
109-
projectId !== null &&
110-
snapshot !== null &&
111-
snapshot.state !== "merged" &&
112-
detectSourceControlProviderFromRemoteUrl(link.url)?.kind === "github"
115+
projectId !== null && snapshot !== null && snapshot.state !== "merged"
113116
? {
114117
environmentId: threadRef.environmentId,
115118
projectId,
@@ -246,7 +249,11 @@ function LinkRow({
246249
/>
247250
</a>
248251
{actionEntry !== null ? (
249-
<PullRequestSpeedActions entry={actionEntry} visible={speedMode} />
252+
<PullRequestSpeedActions
253+
entry={actionEntry}
254+
hostActions={linkHostActions}
255+
visible={speedMode}
256+
/>
250257
) : null}
251258
{/* Out of the row's flow, so no row reserves a column for a button only the hovered one
252259
shows. It sits over the right end of the second line on the row's own hover color,

‎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
});

‎apps/web/src/routes/_chat.pull-requests.tsx‎

Lines changed: 27 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ import {
8888
pullRequestOverrideAfterAction,
8989
reusePullRequestEntries,
9090
settlePullRequestOverrides,
91+
pullRequestHostActions,
9192
} from "../components/pullRequest/pullRequestList.logic";
9293
import {
9394
pullRequestListPreferences,
@@ -1592,6 +1593,22 @@ function PullRequestsRouteView() {
15921593
]);
15931594
/** What is actually on screen once the reader's pending answers are on the rows. */
15941595
const shownCount = displayGroups.reduce((count, group) => count + group.entries.length, 0);
1596+
// The provider list is the workspace's hosts, not the filtered ones, so switching to a host
1597+
// cannot make the switcher that got you there disappear.
1598+
const [hosts, setHosts] = useState<PullRequestListResult["providers"]>([]);
1599+
useEffect(() => {
1600+
// Only from an answer to these filters. Rows carried over from the previous ones bring the
1601+
// host summaries of the question they answered, and coming back from one host to all of them
1602+
// would take the switcher's other hosts out of it on the strength of the narrowed answer.
1603+
if (answered === null) return;
1604+
// An unfiltered response is the full set of hosts. A filtered one only seeds the switcher
1605+
// when there is nothing to seed it with, which is a link that arrived already scoped.
1606+
setHosts((previous) =>
1607+
search.host === undefined || previous.length === 0 ? answered.providers : previous,
1608+
);
1609+
}, [answered, search.host]);
1610+
const showProvider = hosts.length > 1;
1611+
const hostActionsOf = useMemo(() => pullRequestHostActions(hosts), [hosts]);
15951612
const [closeSweepKeys, setCloseSweepKeys] = useState<ReadonlySet<string>>(() => new Set());
15961613
const closeSensorRef = useRef<SidebarPointerSensor | null>(null);
15971614
const closeSweepRows = useMemo(
@@ -1605,8 +1622,14 @@ function PullRequestsRouteView() {
16051622
),
16061623
[displayGroups],
16071624
);
1608-
const closeSweepRef = useRef({ displayGroups, closeSweepRows, closingKeys, closeBatch });
1609-
closeSweepRef.current = { displayGroups, closeSweepRows, closingKeys, closeBatch };
1625+
const closeSweepRef = useRef({
1626+
displayGroups,
1627+
closeSweepRows,
1628+
closingKeys,
1629+
closeBatch,
1630+
hostActionsOf,
1631+
});
1632+
closeSweepRef.current = { displayGroups, closeSweepRows, closingKeys, closeBatch, hostActionsOf };
16101633
useEffect(() => () => closeSensorRef.current?.cancel(), [filterKey, search.q, sort]);
16111634
useEffect(() => {
16121635
const onKeyDown = (event: KeyboardEvent) => {
@@ -1632,7 +1655,7 @@ function PullRequestsRouteView() {
16321655
return (
16331656
row?.groupKey === group.key &&
16341657
row.entry.state === "open" &&
1635-
row.entry.provider === "github" &&
1658+
closeSweepRef.current.hostActionsOf(row.entry).has("close") &&
16361659
!closeSweepRef.current.closingKeys.has(key) &&
16371660
!scrollRef.current?.querySelector(
16381661
`[data-pull-request-key="${CSS.escape(key)}"] [data-pull-request-action-pending="true"]`,
@@ -1766,21 +1789,6 @@ function PullRequestsRouteView() {
17661789
selectSurfaceInUrl(selectedPullRequestSurface);
17671790
};
17681791

1769-
// The provider list is the workspace's hosts, not the filtered ones, so switching to a host
1770-
// cannot make the switcher that got you there disappear.
1771-
const [hosts, setHosts] = useState<PullRequestListResult["providers"]>([]);
1772-
useEffect(() => {
1773-
// Only from an answer to these filters. Rows carried over from the previous ones bring the
1774-
// host summaries of the question they answered, and coming back from one host to all of them
1775-
// would take the switcher's other hosts out of it on the strength of the narrowed answer.
1776-
if (answered === null) return;
1777-
// An unfiltered response is the full set of hosts. A filtered one only seeds the switcher
1778-
// when there is nothing to seed it with, which is a link that arrived already scoped.
1779-
setHosts((previous) =>
1780-
search.host === undefined || previous.length === 0 ? answered.providers : previous,
1781-
);
1782-
}, [answered, search.host]);
1783-
const showProvider = hosts.length > 1;
17841792
// The workspace's own projects already name their hosts, so the row's shape is known before
17851793
// the list is. Only its shape: which hosts can actually be read still comes from the server.
17861794
const expectedHosts = useMemo(() => {
@@ -1942,6 +1950,7 @@ function PullRequestsRouteView() {
19421950
}
19431951
onSelect={selectEntry}
19441952
speedMode={speedMode}
1953+
hostActions={hostActionsOf(entry)}
19451954
onActed={onSpeedAction}
19461955
closing={closingKeys.has(entryKey)}
19471956
sweeping={closeSweepKeys.has(entryKey)}

0 commit comments

Comments
 (0)