Skip to content

Commit 6aaa007

Browse files
refactor(source-control): forges handle their own listing and SSH host quirks
Two flags still made the shared pull request service compensate for one forge, and the order that decides which forge owns a URL or remote was written twice. GitHub search can answer for a renamed repository with silence. `listsAcrossMayOmitRepositories` had the service track which repositories search had shown, for how long, and on which slice. The GitHub adapter now keeps that cache and returns the repositories it cannot vouch for as `unresolved`; the service reads those on their own without knowing why. A Forgejo SSH remote names an alias, not the web server. `sshRemoteHidesWebHost` had the service rewrite a recognised Forgejo provider to "unknown" to force discovery, then take the web host from the result. Source control providers now have an optional `resolveRemoteWebHost`; Forgejo answers it from the login that serves the remote, and the service uses whatever host it returns. The definitions and their precedence now live in a small `@t3tools/source-control-definitions` package that the server and clients both import, and a server test checks its driver list matches them. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 80f2719 commit 6aaa007

20 files changed

Lines changed: 559 additions & 298 deletions

File tree

‎apps/server/package.json‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
"@t3tools/source-control-azure-devops": "workspace:*",
5252
"@t3tools/source-control-bitbucket": "workspace:*",
5353
"@t3tools/source-control-core": "workspace:*",
54+
"@t3tools/source-control-definitions": "workspace:*",
5455
"@t3tools/source-control-forgejo": "workspace:*",
5556
"@t3tools/source-control-gitcafe": "workspace:*",
5657
"@t3tools/source-control-github": "workspace:*",

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

Lines changed: 67 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ import * as SqlitePersistence from "../persistence/Sqlite.ts";
2727
import * as PullRequestFilesViewed from "../persistence/PullRequestFilesViewed.ts";
2828
import * as RepositoryIdentityResolver from "../project/RepositoryIdentityResolver.ts";
2929
import * as SourceControlProviderRegistry from "../sourceControl/SourceControlProviderRegistry.ts";
30+
import type { SourceControlProvider } from "@t3tools/source-control-core/server/SourceControlProvider";
31+
import { isSshRemoteUrl } from "@t3tools/shared/sourceControl";
3032
import * as SourceControlRateLimit from "@t3tools/source-control-core/server/SourceControlRateLimit";
3133
import { fakePullRequestProvider } from "@t3tools/source-control-testing/fakeSourceControlDriver";
3234
import {
@@ -170,6 +172,26 @@ const keyedByCanonicalKey = {
170172
repositoryKey: ({ canonicalKey }: { readonly canonicalKey: string }) => canonicalKey,
171173
};
172174

175+
/** A host whose SSH remotes name an alias, so discovery says which server serves them. */
176+
const sshAliasHost = {
177+
resolveRemoteWebHost: ({ cwd, context, resolveContext }) =>
178+
isSshRemoteUrl(context.remoteUrl)
179+
? resolveContext({
180+
cwd,
181+
context: {
182+
...context,
183+
provider: { kind: SourceControlProviderKind.make("unknown"), name: "", baseUrl: "" },
184+
},
185+
}).pipe(
186+
Effect.map((resolved) =>
187+
resolved === null || resolved.provider.kind === "unknown"
188+
? null
189+
: new URL(resolved.provider.baseUrl).host,
190+
),
191+
)
192+
: Effect.succeed(null),
193+
} as SourceControlProvider["Service"];
194+
173195
function makeService(input: {
174196
readonly settings?: ServerSettings;
175197
readonly projects: ReadonlyArray<OrchestrationProjectShell>;
@@ -193,6 +215,10 @@ function makeService(input: {
193215
resolveLink: () => undefined,
194216
resolveHandle:
195217
input.resolveHandle ?? (() => Effect.die("Unexpected provider refinement")),
218+
get: (kind) =>
219+
Effect.succeed(
220+
kind === "forgejo" ? sshAliasHost : ({} as SourceControlProvider["Service"]),
221+
),
196222
}),
197223
Layer.mock(ProjectService.ProjectService)({
198224
listShells: (options) =>
@@ -2191,7 +2217,6 @@ it.effect("carries every repository of a slice on from the oldest row in it", ()
21912217
],
21922218
providers: [
21932219
fakePullRequestProvider(SourceControlProviderKind.make("github"), {
2194-
listsAcrossMayOmitRepositories: true,
21952220
listChangeRequestsAcross: () =>
21962221
Effect.succeed({
21972222
items: [
@@ -2200,6 +2225,7 @@ it.effect("carries every repository of a slice on from the oldest row in it", ()
22002225
batchedChangeRequest(3, "acme/web", "2026-07-02T00:00:00Z"),
22012226
],
22022227
truncated: true,
2228+
unresolved: ["acme/docs"],
22032229
}),
22042230
}),
22052231
],
@@ -2283,51 +2309,49 @@ it.effect("reads a workspace larger than one search in chunks, and merges them",
22832309
assert.strictEqual(result.entries.length, 101);
22842310
}),
22852311
);
2286-
it.effect(
2287-
"asks on its own for a repository a search answered nothing for, where searches can omit one",
2288-
() =>
2289-
Effect.gen(function* () {
2290-
const separately: string[] = [];
2291-
const service = yield* makeService({
2292-
projects: [
2293-
project({ id: "p1", title: "web", workspaceRoot: "/a", repository: "acme/web" }),
2294-
project({ id: "p2", title: "docs", workspaceRoot: "/b", repository: "acme/docs" }),
2295-
],
2296-
providers: [
2297-
fakePullRequestProvider(SourceControlProviderKind.make("github"), {
2298-
listsAcrossMayOmitRepositories: true,
2299-
listChangeRequests: ({ repository }) => {
2300-
separately.push(repository);
2301-
return repository === "acme/docs"
2302-
? Effect.fail(requestFailed)
2303-
: Effect.succeed({ items: [], truncated: false, continues: true });
2304-
},
2305-
listChangeRequestsAcross: () =>
2306-
Effect.succeed({
2307-
items: [batchedChangeRequest(1, "acme/web", "2026-07-03T00:00:00Z")],
2308-
truncated: false,
2309-
}),
2310-
}),
2311-
],
2312-
});
2312+
it.effect("asks on its own for a repository a search could not vouch for", () =>
2313+
Effect.gen(function* () {
2314+
const separately: string[] = [];
2315+
const service = yield* makeService({
2316+
projects: [
2317+
project({ id: "p1", title: "web", workspaceRoot: "/a", repository: "acme/web" }),
2318+
project({ id: "p2", title: "docs", workspaceRoot: "/b", repository: "acme/docs" }),
2319+
],
2320+
providers: [
2321+
fakePullRequestProvider(SourceControlProviderKind.make("github"), {
2322+
listChangeRequests: ({ repository }) => {
2323+
separately.push(repository);
2324+
return repository === "acme/docs"
2325+
? Effect.fail(requestFailed)
2326+
: Effect.succeed({ items: [], truncated: false, continues: true });
2327+
},
2328+
listChangeRequestsAcross: () =>
2329+
Effect.succeed({
2330+
items: [batchedChangeRequest(1, "acme/web", "2026-07-03T00:00:00Z")],
2331+
truncated: false,
2332+
unresolved: ["acme/docs"],
2333+
}),
2334+
}),
2335+
],
2336+
});
23132337

2314-
const result = yield* service.list({ state: "open" });
2338+
const result = yield* service.list({ state: "open" });
23152339

2316-
assert.deepStrictEqual(separately, ["acme/docs"]);
2317-
assert.deepStrictEqual(result.errors, [
2318-
{
2319-
projectId: "p2" as ProjectId,
2320-
projectTitle: "docs",
2321-
message: "acme/docs could not be read.",
2322-
},
2323-
]);
2324-
assert.deepStrictEqual(
2325-
result.entries.map((entry) => entry.number),
2326-
[1],
2327-
);
2328-
}),
2340+
assert.deepStrictEqual(separately, ["acme/docs"]);
2341+
assert.deepStrictEqual(result.errors, [
2342+
{
2343+
projectId: "p2" as ProjectId,
2344+
projectTitle: "docs",
2345+
message: "acme/docs could not be read.",
2346+
},
2347+
]);
2348+
assert.deepStrictEqual(
2349+
result.entries.map((entry) => entry.number),
2350+
[1],
2351+
);
2352+
}),
23292353
);
2330-
it.effect("believes a search's silence about a repository where searches cover every one", () =>
2354+
it.effect("believes a search's silence about a repository it vouches for", () =>
23312355
Effect.gen(function* () {
23322356
const separately: string[] = [];
23332357
const service = yield* makeService({

0 commit comments

Comments
 (0)