Skip to content

Commit 4fbba6d

Browse files
refactor(source-control): GitHub lives in @t3tools/source-control-github
The GitHub REST/GraphQL transport, credentials, quota reserve, repository provider, pull request API and provider, JSON decoding, conditional checks and stack actions move into their own package. Its driver joins BUILT_IN_SOURCE_CONTROL_DRIVERS, so every host is now a driver: both registries just iterate the list, whose order is discovery's order. - githubQuota is a service module and is renamed GitHubQuota. - SourceControlHost.git gains execute and resolveCommit, which GitHub's plain-git checkout needs. - TestSourceControlHostSettings lets package tests patch settings the way a client write does. - The built-in drivers' layer carries GitHubApi.layerWithDependencies, so the server builds one GitHub quota reserve and rate-limit pause. - The stack-rebase test runs real git through ServerSourceControlHost, so it stays in the server. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent b108c25 commit 4fbba6d

51 files changed

Lines changed: 413 additions & 195 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎apps/server/package.json‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
"@t3tools/source-control-bitbucket": "workspace:*",
5050
"@t3tools/source-control-core": "workspace:*",
5151
"@t3tools/source-control-forgejo": "workspace:*",
52+
"@t3tools/source-control-github": "workspace:*",
5253
"@t3tools/source-control-gitlab": "workspace:*",
5354
"effect": "catalog:",
5455
"jose": "catalog:",

‎apps/server/scripts/evaluate-thread-titles.ts‎

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import {
2323
} from "@t3tools/provider-core/server/threadTitleContext";
2424
import * as ThreadTitleLinks from "../src/textGeneration/ThreadTitleLinks.ts";
2525
import * as SourceControlProviderRegistry from "../src/sourceControl/SourceControlProviderRegistry.ts";
26-
import * as GitHubApi from "../src/sourceControl/GitHubApi.ts";
26+
import * as GitHubApi from "@t3tools/source-control-github/server/GitHubApi";
2727
import * as SourceControlBuiltInDrivers from "../src/sourceControl/builtInDrivers.ts";
2828
import * as ServerSettings from "../src/serverSettings.ts";
2929
import * as VcsProcess from "../src/vcs/VcsProcess.ts";
@@ -147,9 +147,7 @@ await Effect.runPromise(
147147
Layer.mergeAll(
148148
ProcessRunner.layer,
149149
SourceControlProviderRegistry.layer.pipe(
150-
Layer.provide(
151-
Layer.mergeAll(GitHubApi.layerWithDependencies, SourceControlBuiltInDrivers.layer),
152-
),
150+
Layer.provide(SourceControlBuiltInDrivers.layer),
153151
// Default settings: no saved Bitbucket token, gh's own GitHub account choice.
154152
Layer.provide(ServerSettings.layerTest()),
155153
Layer.provide(VcsDriverRegistry.layer.pipe(Layer.provide(VcsProjectConfig.layer))),

‎apps/server/scripts/measure-pr-preview.ts‎

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,19 @@ import * as Option from "effect/Option";
1010
import * as Schema from "effect/Schema";
1111
import { FetchHttpClient } from "effect/http";
1212

13-
import * as GitHubPullRequestApi from "../src/pullRequest/GitHubPullRequestApi.ts";
14-
import * as GitHubPullRequestProvider from "../src/pullRequest/GitHubPullRequestProvider.ts";
15-
import * as GitHubApi from "../src/sourceControl/GitHubApi.ts";
16-
import * as GitHubCredentials from "../src/sourceControl/GitHubCredentials.ts";
13+
import * as GitHubPullRequestApi from "@t3tools/source-control-github/server/GitHubPullRequestApi";
14+
import * as GitHubPullRequestProvider from "@t3tools/source-control-github/server/GitHubPullRequestProvider";
15+
import * as GitHubApi from "@t3tools/source-control-github/server/GitHubApi";
16+
import * as GitHubCredentials from "@t3tools/source-control-github/server/GitHubCredentials";
17+
import * as ServerConfig from "../src/config.ts";
1718
import * as ServerSettings from "../src/serverSettings.ts";
18-
import * as GitHubQuota from "../src/sourceControl/githubQuota.ts";
19+
import * as GitHubQuota from "@t3tools/source-control-github/server/GitHubQuota";
1920
import * as SourceControlRateLimit from "@t3tools/source-control-core/server/SourceControlRateLimit";
21+
import * as ServerSourceControlHost from "../src/sourceControl/ServerSourceControlHost.ts";
22+
import * as GitVcsDriver from "../src/vcs/GitVcsDriver.ts";
23+
import * as VcsDriverRegistry from "../src/vcs/VcsDriverRegistry.ts";
2024
import * as VcsProcess from "../src/vcs/VcsProcess.ts";
25+
import * as VcsProjectConfig from "../src/vcs/VcsProjectConfig.ts";
2126

2227
const [repository, ...numbers] = process.argv.slice(2);
2328
if (!repository || numbers.length === 0 || numbers.some((number) => !/^\d+$/.test(number))) {
@@ -41,6 +46,17 @@ function withRateLimit(query: string): string {
4146
: `${query.slice(0, end)}\n rateLimit { cost }\n${query.slice(end)}`;
4247
}
4348

49+
// The server's host port over default settings: gh's own account choice, no saved token.
50+
const sourceControlHost = ServerSourceControlHost.layer.pipe(
51+
Layer.provide(VcsDriverRegistry.layer.pipe(Layer.provide(VcsProjectConfig.layer))),
52+
Layer.provide(GitVcsDriver.layer),
53+
Layer.provide(ServerSettings.layerTest()),
54+
// A scratch state directory, so nothing here touches a real T3 home.
55+
Layer.provide(ServerConfig.layerTest(process.cwd(), { prefix: "t3-measure-pr-preview-" })),
56+
Layer.provideMerge(VcsProcess.layer),
57+
Layer.provideMerge(NodeServices.layer),
58+
);
59+
4460
const measuredApi = Layer.effect(
4561
GitHubApi.GitHubApi,
4662
Effect.gen(function* () {
@@ -73,18 +89,15 @@ const measuredApi = Layer.effect(
7389
});
7490
}),
7591
).pipe(
76-
Layer.provide(GitHubCredentials.layer.pipe(Layer.provide(ServerSettings.layerTest()))),
92+
Layer.provide(GitHubCredentials.layer),
7793
Layer.provide(GitHubQuota.layer),
7894
Layer.provide(SourceControlRateLimit.layer),
7995
Layer.provide(FetchHttpClient.layer),
80-
Layer.provide(VcsProcess.layer),
81-
Layer.provide(NodeServices.layer),
8296
);
8397

8498
const services = GitHubPullRequestApi.layer.pipe(
8599
Layer.provideMerge(measuredApi),
86-
Layer.provideMerge(VcsProcess.layer),
87-
Layer.provideMerge(NodeServices.layer),
100+
Layer.provideMerge(sourceControlHost),
88101
);
89102

90103
const encodeJson = Schema.encodeSync(Schema.fromJsonString(Schema.Unknown));

‎apps/server/src/assets/AssetAccess.test.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ import { ASSET_ROUTE_PREFIX, issueAssetUrl, resolveAsset } from "./AssetAccess.t
3535
import * as NativeAppIconResolver from "./NativeAppIconResolver.ts";
3636
import { openMediaFile } from "./MediaFile.ts";
3737
import { symlinksSupported } from "@t3tools/shared/testing/symlinks";
38-
import * as GitHubCredentials from "../sourceControl/GitHubCredentials.ts";
38+
import * as GitHubCredentials from "@t3tools/source-control-github/server/GitHubCredentials";
3939
import { githubMediaResponse } from "./GitHubMediaFetch.ts";
4040

4141
vi.mock("node:fs/promises", async (importOriginal) => {

‎apps/server/src/assets/GitHubMediaFetch.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import {
1212
type HttpClientResponse,
1313
} from "effect/http";
1414

15-
import * as GitHubCredentials from "../sourceControl/GitHubCredentials.ts";
15+
import * as GitHubCredentials from "@t3tools/source-control-github/server/GitHubCredentials";
1616

1717
/**
1818
* Exactly the hosts the credential is for. Everything a redirect leads to — the presigned

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ import {
4343
ThreadId,
4444
} from "@t3tools/contracts";
4545
import * as DateTime from "effect/DateTime";
46-
import { decodeGitHubPullRequestListJson } from "../sourceControl/gitHubPullRequests.ts";
46+
import { decodeGitHubPullRequestListJson } from "@t3tools/source-control-github/server/gitHubPullRequests";
4747
import * as GitLabCli from "@t3tools/source-control-gitlab/server/GitLabCli";
4848
import type * as SourceControlHost from "@t3tools/source-control-core/server/SourceControlHost";
4949
import * as TestSourceControlHost from "@t3tools/source-control-testing/TestSourceControlHost";

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@ import { assert, it } from "@effect/vitest";
22

33
import * as AzureDevOpsCli from "@t3tools/source-control-azure-devops/server/AzureDevOpsCli";
44
import * as BitbucketApi from "@t3tools/source-control-bitbucket/server/BitbucketApi";
5-
import * as GitHubApi from "../sourceControl/GitHubApi.ts";
5+
import * as GitHubApi from "@t3tools/source-control-github/server/GitHubApi";
66
import * as SourceControlRateLimit from "@t3tools/source-control-core/server/SourceControlRateLimit";
77
import * as GitLabCli from "@t3tools/source-control-gitlab/server/GitLabCli";
88
import { azureDevOpsProviderFailure } from "@t3tools/source-control-azure-devops/server/AzureDevOpsPullRequestProvider";
99
import { bitbucketProviderFailure } from "@t3tools/source-control-bitbucket/server/BitbucketPullRequestProvider";
10-
import { gitHubProviderFailure } from "./GitHubPullRequestProvider.ts";
10+
import { gitHubProviderFailure } from "@t3tools/source-control-github/server/GitHubPullRequestProvider";
1111
import { gitLabProviderFailure } from "@t3tools/source-control-gitlab/server/GitLabPullRequestProvider";
1212

1313
const cause = new Error("redacted provider failure");

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

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,6 @@ import * as Effect from "effect/Effect";
33
import * as Layer from "effect/Layer";
44
import type { SourceControlProviderKind } from "@t3tools/contracts";
55

6-
import * as GitHubApi from "../sourceControl/GitHubApi.ts";
7-
import * as GitHubPullRequestApi from "./GitHubPullRequestApi.ts";
8-
import * as GitHubPullRequestProvider from "./GitHubPullRequestProvider.ts";
96
import * as BuiltInDrivers from "../sourceControl/builtInDrivers.ts";
107
import type { PullRequestProviderApi } from "@t3tools/source-control-core/server/PullRequestProvider";
118

@@ -36,24 +33,14 @@ export function fromProviders(
3633
* @public Service construction is part of the canonical Effect module API.
3734
*/
3835
export const make = Effect.gen(function* () {
39-
const providers = yield* Effect.all([GitHubPullRequestProvider.make]);
4036
const drivers = yield* Effect.forEach(BuiltInDrivers.BUILT_IN_SOURCE_CONTROL_DRIVERS, (driver) =>
4137
driver.make.pipe(Effect.map((instance) => instance.pullRequests)),
4238
);
43-
return fromProviders([
44-
...providers,
45-
...drivers.filter((provider): provider is PullRequestProviderApi => provider !== null),
46-
]);
39+
return fromProviders(
40+
drivers.filter((provider): provider is PullRequestProviderApi => provider !== null),
41+
);
4742
});
4843

4944
export const layer = Layer.effect(PullRequestProviderRegistry, make).pipe(
50-
Layer.provide(
51-
GitHubPullRequestApi.layer.pipe(
52-
Layer.provide(
53-
// Built here too, so a registry built alone still has one budget and pause per host.
54-
GitHubApi.layerWithDependencies,
55-
),
56-
),
57-
),
5845
Layer.provide(BuiltInDrivers.layer),
5946
);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ import {
7777
import { resolveProjectSettings } from "@t3tools/shared/projectSettings";
7878
import { detectSourceControlProviderFromRemoteUrl } from "@t3tools/shared/sourceControl";
7979

80-
import { AllowGitHubReserve } from "../sourceControl/GitHubApi.ts";
80+
import { AllowGitHubReserve } from "@t3tools/source-control-github/server/GitHubApi";
8181
import * as ProjectService from "../project/ProjectService.ts";
8282
import * as ServerSettings from "../serverSettings.ts";
8383
import * as PullRequestFilesViewed from "../persistence/PullRequestFilesViewed.ts";

‎apps/server/src/server.ts‎

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ import * as ProviderHostLive from "./provider/ProviderHostLive.ts";
5252
import * as AcpRegistrySupport from "@t3tools/provider-acp-registry/server/AcpRegistrySupport";
5353
import * as CheckpointDiffQuery from "./checkpointing/CheckpointDiffQuery.ts";
5454
import * as CheckpointStore from "./checkpointing/CheckpointStore.ts";
55-
import * as GitHubApi from "./sourceControl/GitHubApi.ts";
5655
import * as ForgejoCli from "@t3tools/source-control-forgejo/server/ForgejoCli";
5756
import * as SourceControlBuiltInDrivers from "./sourceControl/builtInDrivers.ts";
5857
import * as TextGeneration from "./textGeneration/TextGeneration.ts";
@@ -296,7 +295,7 @@ const layerPersistence = Layer.empty.pipe(Layer.provideMerge(SqlitePersistence.l
296295
const layerVcsDriverRegistry = VcsDriverRegistry.layer.pipe(Layer.provide(VcsProjectConfig.layer));
297296

298297
const layerSourceControlProviderRegistry = SourceControlProviderRegistry.layer.pipe(
299-
Layer.provide(Layer.mergeAll(GitHubApi.layerWithDependencies, SourceControlBuiltInDrivers.layer)),
298+
Layer.provideMerge(SourceControlBuiltInDrivers.layer),
300299
Layer.provideMerge(GitVcsDriver.layer),
301300
Layer.provideMerge(layerVcsDriverRegistry),
302301
);
@@ -585,9 +584,9 @@ const layerRuntimeCoreDependenciesBase = Layer.mergeAll(
585584
Layer.provideMerge(RuntimeLayer.layerEventInfrastructure),
586585
Layer.provideMerge(Layer.merge(ProjectStore.layer, ThreadSearch.layer)),
587586
Layer.provideMerge(layerServerSettings),
588-
// The asset route uses the registry's GitHub credential for private PR media.
587+
// The asset route uses the registry's GitHub credential for private PR media, which the
588+
// built-in drivers' layer provides alongside the registry.
589589
Layer.provideMerge(layerSourceControlProviderRegistry),
590-
Layer.provideMerge(GitHubApi.layerWithDependencies),
591590
Layer.provideMerge(layerGit),
592591
Layer.provideMerge(layerVcs),
593592
Layer.provideMerge(Layer.mergeAll(layerTerminal, layerPreview, layerDevice)),

0 commit comments

Comments
 (0)