Skip to content

Commit 0e4df51

Browse files
refactor(source-control): forges recognise their own remotes and repository keys
Shared and contracts held every forge's remote host rules, Azure DevOps's repository key spellings (twice, plus a byte-for-byte copy in the server), the Azure repository selector, and Forgejo's port-carrying change request host, and the pull request service special-cased Forgejo SSH remotes, dev.azure.com keys and a hardcoded list of public hosts. Each forge's client definition now owns these behind hooks: recognizeRemote, changeRequestHost, repositorySelector, repositoryKeyFromRemote, canonicalRepositoryKey and sshRemoteHidesWebHost. The registry asks them in an explicit recognition order that reproduces the old precedence, and falls back to an unknown host. normalizeGitRemoteUrl is forge-neutral; persisted keys come from the registry's repositoryKeyFromRemote, which keeps the old output byte for byte (checked against a snapshot of every old function on ~90 remotes and keys). pullRequestHostOf, detectSourceControlProviderFromRemoteUrl, canonicalRepositoryKey, sourceControlRepositorySelector and the GitHub-only remote parser are gone. RepositoryIdentity.provider is now a SourceControlProviderKind; the encoded value is unchanged. Behaviour changes: agent session import names a project's repository for every forge, not only GitHub. Forgejo's definition names codeberg.org as its public host. The GitHub, GitLab and Bitbucket plugins consult only their own recogniser, so a hostname carrying two forges' labels can now read as theirs inside that plugin. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 33a63a3 commit 0e4df51

67 files changed

Lines changed: 958 additions & 718 deletions

File tree

Some content is hidden

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

‎apps/mobile/src/features/pull-requests/pullRequestNavigation.test.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { EnvironmentId, ProjectId } from "@t3tools/contracts";
1+
import { EnvironmentId, ProjectId, SourceControlProviderKind } from "@t3tools/contracts";
22
import { describe, expect, it } from "vite-plus/test";
33
import { nativePullRequestDestination } from "../../lib/pullRequestNavigation";
44

@@ -10,7 +10,7 @@ const project = (id: string, canonicalKey: string, provider: string, remoteUrl:
1010
canonicalKey,
1111
locator: { source: "git-remote" as const, remoteName: "origin", remoteUrl },
1212
displayName: canonicalKey.split("/").slice(1).join("/"),
13-
provider,
13+
provider: SourceControlProviderKind.make(provider),
1414
},
1515
});
1616
const projects = [

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

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -49,15 +49,12 @@ import {
4949
resolveProjectSettings,
5050
} from "@t3tools/shared/projectSettings";
5151
import {
52-
detectSourceControlProviderFromGitRemoteUrl,
5352
mergeGitStatusParts,
54-
normalizeGitRemoteUrl,
5553
resolveAutoFeatureBranchName,
5654
sanitizeBranchFragment,
5755
sanitizeFeatureBranchName,
5856
} from "@t3tools/shared/git";
5957
import {
60-
canonicalRepositoryKey,
6158
getChangeRequestTerminologyForKind,
6259
isSshRemoteUrl,
6360
type ChangeRequestTerminology,
@@ -268,7 +265,7 @@ export function pullRequestRepositoryKey(value: string): string | null {
268265
url.pathname = match[1];
269266
url.search = "";
270267
url.hash = "";
271-
return normalizeGitRemoteUrl(url.toString());
268+
return sourceControlClients.repositoryKeyFromRemote(url.toString());
272269
} catch {
273270
return null;
274271
}
@@ -1027,8 +1024,10 @@ export const make = Effect.gen(function* () {
10271024
if (
10281025
remoteUrl === null ||
10291026
pullRequestKey === null ||
1030-
canonicalRepositoryKey(pullRequestKey) !==
1031-
canonicalRepositoryKey(normalizeGitRemoteUrl(remoteUrl))
1027+
sourceControlClients.canonicalRepositoryKey(pullRequestKey) !==
1028+
sourceControlClients.canonicalRepositoryKey(
1029+
sourceControlClients.repositoryKeyFromRemote(remoteUrl),
1030+
)
10321031
) {
10331032
return yield* cause;
10341033
}
@@ -1451,7 +1450,7 @@ export const make = Effect.gen(function* () {
14511450
const baseUrl =
14521451
remote.remoteUrl === null
14531452
? undefined
1454-
: detectSourceControlProviderFromGitRemoteUrl(remote.remoteUrl)?.baseUrl;
1453+
: sourceControlClients.recognizeRemote(remote.remoteUrl)?.baseUrl;
14551454
const host = baseUrl === undefined ? null : urlHost(baseUrl);
14561455
const repository = remote.repositoryNameWithOwner?.toLowerCase();
14571456
const fromEnvironment = parseGitHubRepositorySelector(environment.GH_REPO ?? "", host ?? "");
@@ -1485,7 +1484,7 @@ export const make = Effect.gen(function* () {
14851484
(yield* readConfigValueNullable(cwd, `remote.${preferredRemoteName}.url`)) ??
14861485
(yield* readConfigValueNullable(cwd, "remote.origin.url"));
14871486

1488-
const provider = remoteUrl ? detectSourceControlProviderFromGitRemoteUrl(remoteUrl) : null;
1487+
const provider = remoteUrl ? sourceControlClients.recognizeRemote(remoteUrl) : null;
14891488
if (!remoteUrl || provider?.kind !== "unknown") return provider;
14901489
const handle = yield* sourceControlProviders
14911490
.resolveHandle({
@@ -1516,7 +1515,7 @@ export const make = Effect.gen(function* () {
15161515
/^https?:\/\//iu.test(remoteUrl) &&
15171516
(repositoryNameWithOwner?.split("/").length ?? 0) > 2
15181517
) {
1519-
const kind = detectSourceControlProviderFromGitRemoteUrl(remoteUrl)?.kind;
1518+
const kind = sourceControlClients.recognizeRemote(remoteUrl)?.kind;
15201519
const provider =
15211520
kind === undefined
15221521
? undefined
@@ -1527,7 +1526,7 @@ export const make = Effect.gen(function* () {
15271526
}
15281527
return {
15291528
remoteUrl,
1530-
remoteUrlKey: remoteUrl ? normalizeGitRemoteUrl(remoteUrl) : null,
1529+
remoteUrlKey: remoteUrl ? sourceControlClients.repositoryKeyFromRemote(remoteUrl) : null,
15311530
repositoryNameWithOwner,
15321531
ownerLogin: parseRepositoryOwnerLogin(repositoryNameWithOwner),
15331532
};
@@ -2486,7 +2485,9 @@ export const make = Effect.gen(function* () {
24862485
remoteName === null
24872486
? Effect.succeed(null)
24882487
: readConfig(`remote.${remoteName}.url`).pipe(
2489-
Effect.map((remoteUrl) => (remoteUrl ? normalizeGitRemoteUrl(remoteUrl) : null)),
2488+
Effect.map((remoteUrl) =>
2489+
remoteUrl ? sourceControlClients.repositoryKeyFromRemote(remoteUrl) : null,
2490+
),
24902491
);
24912492
const remoteName = remoteNameOverride ?? (yield* readConfig(`branch.${branch}.remote`));
24922493
const [headRemoteUrlKey, targetRemoteUrlKey] =

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66
type GitRunStackedActionResult,
77
type OrchestrationV2ServerCommand as OrchestrationCommand,
88
type OrchestrationProjectShell,
9+
SourceControlProviderKind,
910
} from "@t3tools/contracts";
1011
import { describe, expect, it } from "@effect/vitest";
1112
import * as Effect from "effect/Effect";
@@ -40,7 +41,7 @@ const project: OrchestrationProjectShell = {
4041
remoteName: "origin",
4142
remoteUrl: "[email protected]:Platform/API.git",
4243
},
43-
provider: "github",
44+
provider: SourceControlProviderKind.make("github"),
4445
displayName: "Platform/API",
4546
owner: "Platform",
4647
name: "API",

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

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
1-
import { sourceControlRepositorySelector } from "@t3tools/shared/sourceControl";
21
import {
32
type CommandId,
4-
pullRequestHostOf,
53
type GitRunStackedActionResult,
64
type OrchestrationProjectShell,
7-
type SourceControlProviderKind,
85
type ThreadId,
96
} from "@t3tools/contracts";
107
import * as Cause from "effect/Cause";
@@ -35,11 +32,11 @@ export function createdPullRequestKey(
3532
return { host: parsed.host, repository: parsed.repository, number: parsed.number, url };
3633
}
3734
const identity = project?.repositoryIdentity;
38-
const kind = identity?.provider as SourceControlProviderKind | undefined;
39-
const repository = sourceControlRepositorySelector(identity);
35+
const kind = identity?.provider;
36+
const repository = sourceControlClients.repositorySelector(identity);
4037
if (!identity || kind === undefined || repository === null) return null;
4138
return {
42-
host: pullRequestHostOf(identity, kind),
39+
host: sourceControlClients.changeRequestHost(identity, kind),
4340
repository: repository.toLowerCase(),
4441
number,
4542
url,

‎apps/server/src/mcp/toolkits/pullRequests/handlers.test.ts‎

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {
99
type PullRequestRef,
1010
type PullRequestReviewGuideResult,
1111
type ThreadPullRequestLink,
12+
SourceControlProviderKind,
1213
} from "@t3tools/contracts";
1314
import { describe, expect, it } from "@effect/vitest";
1415
import * as Crypto from "effect/Crypto";
@@ -64,7 +65,7 @@ function makeProject(
6465
remoteName: "origin",
6566
remoteUrl: "[email protected]:T3Tools/T3Code.git",
6667
},
67-
provider: "github",
68+
provider: SourceControlProviderKind.make("github"),
6869
displayName: "T3Tools/T3Code",
6970
owner: "T3Tools",
7071
name: "T3Code",
@@ -380,7 +381,7 @@ describe("pull request toolkit handlers", () => {
380381
remoteName: "origin",
381382
remoteUrl: "[email protected]:group/sub/project.git",
382383
},
383-
provider: "gitlab",
384+
provider: SourceControlProviderKind.make("gitlab"),
384385
displayName: "group/sub/project",
385386
}),
386387
});
@@ -409,7 +410,7 @@ describe("pull request toolkit handlers", () => {
409410
remoteName: "origin",
410411
remoteUrl: "http://dummy:[email protected]:8080/tfs/Collection/Project/_git/Repo",
411412
},
412-
provider: "unknown",
413+
provider: SourceControlProviderKind.make("unknown"),
413414
displayName: "tfs/collection/project/_git/repo",
414415
}),
415416
});
@@ -586,7 +587,7 @@ describe("pull request guide tools", () => {
586587
remoteName: "origin",
587588
remoteUrl: "[email protected]:acme/web.git",
588589
},
589-
provider: "github",
590+
provider: SourceControlProviderKind.make("github"),
590591
displayName: "acme/web",
591592
owner: "acme",
592593
name: "web",
@@ -645,7 +646,7 @@ describe("pull request guide tools", () => {
645646
remoteName: "origin",
646647
remoteUrl: "https://dev.azure.com/org/project/_git/web",
647648
},
648-
provider: "azure-devops",
649+
provider: SourceControlProviderKind.make("azure-devops"),
649650
displayName: "org/project/_git/web",
650651
owner: "org",
651652
name: "web",

‎apps/server/src/mcp/toolkits/pullRequests/handlers.ts‎

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
import {
22
CommandId,
3-
pullRequestHostOf,
43
type OrchestrationProjectShell,
54
type OrchestrationV2ThreadShell,
65
type SourceControlProviderKind,
76
type ThreadId,
87
type ThreadPullRequestLink,
98
} from "@t3tools/contracts";
10-
import { sourceControlRepositorySelector } from "@t3tools/shared/sourceControl";
119
import * as Cause from "effect/Cause";
1210
import * as Crypto from "effect/Crypto";
1311
import * as Effect from "effect/Effect";
@@ -61,10 +59,10 @@ function projectHostAndProvider(project: OrchestrationProjectShell | undefined):
6159
readonly kind: SourceControlProviderKind | null;
6260
} {
6361
const identity = project?.repositoryIdentity;
64-
const kind = (identity?.provider as SourceControlProviderKind | undefined) ?? null;
62+
const kind = identity?.provider ?? null;
6563
if (!identity || kind === null) return { host: null, kind: null };
6664
return {
67-
host: pullRequestHostOf(identity, kind),
65+
host: sourceControlClients.changeRequestHost(identity, kind),
6866
kind,
6967
};
7068
}
@@ -171,7 +169,7 @@ function projectForPullRequest(
171169
: pullRequestSyncKey(
172170
{
173171
projectId: project.id,
174-
repository: sourceControlRepositorySelector(project.repositoryIdentity) ?? "",
172+
repository: sourceControlClients.repositorySelector(project.repositoryIdentity) ?? "",
175173
number: 1,
176174
},
177175
project.repositoryIdentity,

‎apps/server/src/orchestration-v2/ThreadPullRequestService.test.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ describe("ThreadPullRequestServiceV2 reads", () => {
137137
remoteName: "origin",
138138
remoteUrl: "[email protected]:acme/project.git",
139139
},
140-
provider: "github" as const,
140+
provider: SourceControlProviderKind.make("github"),
141141
owner: "acme",
142142
name: "project",
143143
}),
@@ -261,7 +261,7 @@ describe("ThreadPullRequestServiceV2 reads", () => {
261261
remoteName: "origin",
262262
remoteUrl: "[email protected]:acme/project.git",
263263
},
264-
provider: "github" as const,
264+
provider: SourceControlProviderKind.make("github"),
265265
owner: "acme",
266266
name: "project",
267267
}),

‎apps/server/src/orchestration-v2/ThreadPullRequestService.ts‎

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
import {
2-
canonicalRepositoryKey,
3-
sourceControlRepositorySelector,
4-
} from "@t3tools/shared/sourceControl";
51
import {
62
CommandId,
73
type OrchestrationProjectShell,
@@ -29,6 +25,7 @@ import * as ProjectStore from "./ProjectStore.ts";
2925
import * as PullRequestService from "../pullRequest/PullRequestService.ts";
3026
import * as RepositoryIdentityResolver from "../project/RepositoryIdentityResolver.ts";
3127
import { forkParked } from "../serverActivation.ts";
28+
import { sourceControlClients } from "../sourceControl/sourceControlClients.ts";
3229
import * as Orchestrator from "./Orchestrator.ts";
3330

3431
class ThreadPullRequestServiceV2 extends Context.Service<
@@ -59,8 +56,8 @@ function pullRequestMatchesProject(
5956
return (
6057
pullRequest.repositoryKey !== null &&
6158
project.repositoryIdentity != null &&
62-
canonicalRepositoryKey(pullRequest.repositoryKey) ===
63-
canonicalRepositoryKey(project.repositoryIdentity.canonicalKey)
59+
sourceControlClients.canonicalRepositoryKey(pullRequest.repositoryKey) ===
60+
sourceControlClients.canonicalRepositoryKey(project.repositoryIdentity.canonicalKey)
6461
);
6562
}
6663

@@ -78,7 +75,7 @@ const resolveProjectForPullRequestDiscovery = Effect.fn(
7875
});
7976
return {
8077
project: { ...project, repositoryIdentity },
81-
repository: sourceControlRepositorySelector(repositoryIdentity),
78+
repository: sourceControlClients.repositorySelector(repositoryIdentity),
8279
};
8380
});
8481

‎apps/server/src/orchestration-v2/ThreadSettlementService.ts‎

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import * as ServerSettings from "../serverSettings.ts";
2626
import { forkParked } from "../serverActivation.ts";
2727
import * as TerminalManager from "../terminal/Manager.ts";
2828
import * as ProjectStore from "./ProjectStore.ts";
29+
import { sourceControlClients } from "../sourceControl/sourceControlClients.ts";
2930
import * as Orchestrator from "./Orchestrator.ts";
3031
import * as ProjectionStore from "./ProjectionStore.ts";
3132

@@ -51,18 +52,6 @@ function latestMillis(values: ReadonlyArray<number | null>): number | null {
5152
return latest;
5253
}
5354

54-
function canonicalRepositoryKey(key: string): string {
55-
return key
56-
.replace(
57-
/^(?:ssh\.dev\.azure\.com|vs-ssh\.visualstudio\.com)\/v3\/([^/]+)\/([^/]+)\/([^/]+)$/u,
58-
"dev.azure.com/$1/$2/_git/$3",
59-
)
60-
.replace(
61-
/^([^.]+)\.visualstudio\.com\/(?:defaultcollection\/)?([^/]+)\/_git\/([^/]+)$/u,
62-
"dev.azure.com/$1/$2/_git/$3",
63-
);
64-
}
65-
6655
function pullRequestMatchesProject(
6756
pullRequest: GitManager.GitBranchPullRequest,
6857
project: {
@@ -72,8 +61,8 @@ function pullRequestMatchesProject(
7261
return (
7362
pullRequest.repositoryKey !== null &&
7463
project.repositoryIdentity != null &&
75-
canonicalRepositoryKey(pullRequest.repositoryKey) ===
76-
canonicalRepositoryKey(project.repositoryIdentity.canonicalKey)
64+
sourceControlClients.canonicalRepositoryKey(pullRequest.repositoryKey) ===
65+
sourceControlClients.canonicalRepositoryKey(project.repositoryIdentity.canonicalKey)
7766
);
7867
}
7968

‎apps/server/src/project/AgentSessionScanner.test.ts‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -745,7 +745,7 @@ it.layer(NodeServices.layer)("AgentSessionScanner", (it) => {
745745
yield* fileSystem.makeDirectory(submoduleGitDir, { recursive: true });
746746
yield* fileSystem.writeFileString(
747747
path.join(submoduleGitDir, "config"),
748-
'[remote "origin"]\n\turl = ssh://github.com/pingdotgg/vendor.git\n',
748+
'[remote "origin"]\n\turl = ssh://gitlab.com/pingdotgg/libs/vendor.git\n',
749749
);
750750
yield* fileSystem.writeFileString(
751751
path.join(submodule, ".git"),
@@ -767,7 +767,10 @@ it.layer(NodeServices.layer)("AgentSessionScanner", (it) => {
767767
).toEqual([
768768
{
769769
path: submodule,
770-
git: { remoteKey: "github.com/pingdotgg/vendor", repository: "pingdotgg/vendor" },
770+
git: {
771+
remoteKey: "gitlab.com/pingdotgg/libs/vendor",
772+
repository: "pingdotgg/libs/vendor",
773+
},
771774
},
772775
{ path: noRemote, git: { remoteKey: null, repository: null } },
773776
{ path: plain, git: null },

0 commit comments

Comments
 (0)