Skip to content

Commit 90511fa

Browse files
ulughbeckclaude
andcommitted
feat(server,web): a project can use its own GitHub account
Per-host account choice cannot serve a personal and a work project on the same host. A project's githubAccount setting picks the gh login T3 Code uses for its pull requests and for the pull requests it creates; viewers, searches and batched reads are grouped by account. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 4ce6a51 commit 90511fa

18 files changed

Lines changed: 590 additions & 70 deletions

‎apps/server/src/git/GitManager.ts‎

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ import * as ServerSettings from "../serverSettings.ts";
7373
import type { GitManagerServiceError } from "@t3tools/contracts";
7474
import * as GitVcsDriver from "../vcs/GitVcsDriver.ts";
7575
import * as SourceControlProviderRegistry from "../sourceControl/SourceControlProviderRegistry.ts";
76+
import { makeGitHubProjectAccount } from "../sourceControl/gitHubProjectAccount.ts";
7677
import { detectPrTemplate } from "../sourceControl/PrTemplateDetection.ts";
7778
import type { ChangeRequest } from "@t3tools/contracts";
7879

@@ -2884,18 +2885,24 @@ export const make = Effect.gen(function* () {
28842885
},
28852886
);
28862887

2888+
// Everything that reaches the host runs as the checkout's project account.
2889+
const { actAs } = yield* makeGitHubProjectAccount;
28872890
return GitManager.of({
28882891
createWorktree,
28892892
localStatus,
2890-
remoteStatus,
2891-
status,
2892-
branchPullRequest,
2893+
remoteStatus: (input, options) => actAs(input, remoteStatus(input, options)),
2894+
status: (input) => actAs(input, status(input)),
2895+
branchPullRequest: (input, options) => actAs(input, branchPullRequest(input, options)),
28932896
invalidateLocalStatus,
28942897
invalidateRemoteStatus,
28952898
invalidateStatus,
2896-
resolvePullRequest,
2897-
preparePullRequestThread,
2898-
runStackedAction,
2899+
resolvePullRequest: (input) => actAs(input, resolvePullRequest(input)),
2900+
preparePullRequestThread: (input) => actAs(input, preparePullRequestThread(input)),
2901+
runStackedAction: (input, options) =>
2902+
actAs(
2903+
{ cwd: input.cwd, projectId: input.projectId ?? null },
2904+
runStackedAction(input, options),
2905+
),
28992906
});
29002907
});
29012908

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1765,6 +1765,8 @@ export const make = Effect.gen(function* () {
17651765
Context.getOrElse(context, GitHubApi.PinnedGitHubCredential, () => null)
17661766
?.credentialFingerprint ?? null,
17671767
Context.getOrElse(context, SourceControlRateLimit.CredentialScope, () => ""),
1768+
// A project with its own account is read with its own token, never batched with others.
1769+
Context.getOrElse(context, GitHubApi.GitHubAccount, () => null),
17681770
]),
17691771
resolver: (entries) => {
17701772
const [first] = entries;
@@ -1845,6 +1847,8 @@ export const make = Effect.gen(function* () {
18451847
Context.getOrElse(context, GitHubApi.PinnedGitHubCredential, () => null)
18461848
?.credentialFingerprint ?? null,
18471849
Context.getOrElse(context, SourceControlRateLimit.CredentialScope, () => ""),
1850+
// A project with its own account is read with its own token, never batched with others.
1851+
Context.getOrElse(context, GitHubApi.GitHubAccount, () => null),
18481852
]),
18491853
resolver: (entries) => {
18501854
const [first] = entries;

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

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import * as NodeServices from "@effect/platform-node/NodeServices";
22
import * as ChildProcessSpawner from "effect/process/ChildProcessSpawner";
33
import * as KeyValueStore from "effect/persistence/KeyValueStore";
44
import { assert, it } from "@effect/vitest";
5+
import { GitHubAccount } from "../sourceControl/GitHubApi.ts";
56
import * as Cause from "effect/Cause";
67
import * as Clock from "effect/Clock";
78
import * as Deferred from "effect/Deferred";
@@ -1279,6 +1280,69 @@ it.effect("tries another workspace on the same host for the viewer", () =>
12791280
}),
12801281
);
12811282

1283+
it.effect("runs a project with its own GitHub account as that account, apart from the rest", () =>
1284+
Effect.gen(function* () {
1285+
const searches: Array<{
1286+
readonly viewer: string;
1287+
readonly account: string | null;
1288+
readonly repositories: ReadonlyArray<string>;
1289+
}> = [];
1290+
const statReads: Array<{ readonly account: string | null; readonly count: number }> = [];
1291+
const service = yield* makeService({
1292+
settings: {
1293+
...DEFAULT_SERVER_SETTINGS,
1294+
projectSettingsOverrides: { ["w1" as ProjectId]: { githubAccount: "work" } },
1295+
},
1296+
projects: [
1297+
project({ id: "p1", title: "personal", workspaceRoot: "/p1", repository: "me/one" }),
1298+
project({ id: "p2", title: "other", workspaceRoot: "/p2", repository: "me/two" }),
1299+
project({ id: "w1", title: "work", workspaceRoot: "/w1", repository: "Acme/web" }),
1300+
],
1301+
providers: [
1302+
fakeProvider("github", {
1303+
getViewer: () =>
1304+
Effect.map(GitHubAccount, (account) => (account === null ? "personal" : account)),
1305+
listChangeRequestsAcross: (input) =>
1306+
Effect.map(GitHubAccount, (account) => {
1307+
searches.push({ viewer: input.viewer, account, repositories: input.repositories });
1308+
return {
1309+
items: input.repositories.map((repository, index) =>
1310+
batchedChangeRequest(index + 1, repository, "2026-07-02T00:00:00Z"),
1311+
),
1312+
truncated: false,
1313+
};
1314+
}),
1315+
listChangeRequestStats: (input) =>
1316+
Effect.map(GitHubAccount, (account) => {
1317+
statReads.push({ account, count: input.changeRequests.length });
1318+
return input.changeRequests.map((ref) => ({ ...ref, additions: 1, deletions: 1 }));
1319+
}),
1320+
}),
1321+
],
1322+
});
1323+
const result = yield* service.list({ state: "open", involvement: "all" });
1324+
assert.strictEqual(result.entries.length, 3);
1325+
assert.sameDeepMembers(searches, [
1326+
{ viewer: "personal", account: null, repositories: ["me/one", "me/two"] },
1327+
{ viewer: "work", account: "work", repositories: ["Acme/web"] },
1328+
]);
1329+
assert.strictEqual(result.viewers["github.com"], "personal");
1330+
assert.strictEqual(result.viewers["project:w1"], "work");
1331+
1332+
yield* service.listStats({
1333+
refs: result.entries.map(({ projectId, repository, number }) => ({
1334+
projectId,
1335+
repository,
1336+
number,
1337+
})),
1338+
});
1339+
assert.sameDeepMembers(statReads, [
1340+
{ account: null, count: 2 },
1341+
{ account: "work", count: 1 },
1342+
]);
1343+
}),
1344+
);
1345+
12821346
it.effect("routing verifies the current account on the requested host without caching it", () =>
12831347
Effect.gen(function* () {
12841348
let viewer = "first-account";

0 commit comments

Comments
 (0)