@devries-cameron20 / t3code Mirror · read-only / commits / a774d7f473
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 21, 08:30 UTC

fix(server): issue links on a custom GitHub Enterprise hostname resolve (#38269)

Julius Marminge committed Nov 17, 2026 at 11:13 UTC a774d7f473e968e7ee8911bc9906c97397f4b98a
8 files changed +134 -14
apps/server/src/issue/IssueService.test.ts
+9
@@ -275,6 +275,15 @@ describe("IssueService", () => {
275 host: "gitea.test",
276 });
277
278 + // A GitHub Enterprise Server's hostname need not say "github"; its project vouches for it.
279 + const enterprise = yield* makeService({
280 + projects: [project({ id: "ghes", repository: "acme/web", host: "code.acme.test" })],
281 + trackers: [fakeTracker()],
282 + });
283 + expect(
284 + yield* enterprise.resolveUrl("https://code.acme.test/acme/web/issues/7"),
285 + ).toMatchObject({ projectId: "ghes", host: "code.acme.test", key: "7", writable: true });
286 +
287 // Another host is not reachable through this project's credentials at all.
288 const elsewhere = yield* Effect.flip(service.detail({ ...own, host: "ghe.example.test" }));
289 expect(elsewhere).toMatchObject({
apps/server/src/issue/IssueService.ts
+23 -2
@@ -9,6 +9,7 @@ import {
9 IssueOperationError,
10 IssueTrackerKind,
11 IssueUnavailableError,
12 + SourceControlProviderKind,
13 type IssueCandidates,
14 type IssueCommentInput,
15 type IssueCommentsPage,
@@ -640,10 +641,30 @@ const make = Effect.gen(function* () {
641 return { projectId, tracker: own.tracker, host: own.host, scope: own.scope };
642 });
643
644 + /** A host whose hostname does not name it, such as GitHub Enterprise Server, is vouched for by a project on it. */
645 + const parseOnProjectHost = (value: string) => {
646 + const url = parseUrl(value);
647 + if (url === null) return Effect.succeed(null);
648 + return listProjects({ host: url.hostname, authority: url.host.toLowerCase() }).pipe(
649 + Effect.map(({ supported }) => {
650 + for (const project of supported) {
651 + const parsed = sourceControlDefinitions.parseIssueUrl(
652 + value,
653 + SourceControlProviderKind.make(project.tracker),
654 + );
655 + if (parsed !== null) return parsed;
656 + }
657 + return null;
658 + }),
659 + );
660 + };
661 +
662 const resolveUrl: IssueService["Service"]["resolveUrl"] = Effect.fn("IssueService.resolveUrl")(
663 function* (url, preferredProjectId) {
645 - const gitHost = sourceControlDefinitions.parseIssueUrl(url);
646 - const standalone = gitHost === null ? findStandaloneIssueUrl(registry.standalone, url) : null;
664 + const recognized = sourceControlDefinitions.parseIssueUrl(url);
665 + const standalone =
666 + recognized === null ? findStandaloneIssueUrl(registry.standalone, url) : null;
667 + const gitHost = recognized ?? (standalone === null ? yield* parseOnProjectHost(url) : null);
668 const parsed =
669 gitHost === null
670 ? standalone
packages/client-runtime/src/issueLinks.test.ts
+7
@@ -56,6 +56,13 @@ describe("resolveIssueLinkTarget", () => {
56 ],
57 });
58 expect(target?.ref.projectId).toBe("ported");
59 +
60 + // An Enterprise Server's hostname need not say "github"; its project vouches for it.
61 + const custom = resolveIssueLinkTarget({
62 + url: "https://code.acme.test/acme/web/issues/7",
63 + projects: [enterprise("custom", "code.acme.test")],
64 + });
65 + expect(custom?.ref).toMatchObject({ projectId: "custom", host: "code.acme.test", key: "7" });
66 });
67
68 it.each([
packages/client-runtime/src/issueLinks.ts
+21 -3
@@ -30,6 +30,24 @@ function linkAuthority(url: string): string | null {
30 }
31 }
32
33 +/** A host whose hostname does not name it, such as GitHub Enterprise Server, is vouched for by a project on it. */
34 +function parseIssueLink(
35 + url: string,
36 + authority: string | null,
37 + projects: ReadonlyArray<LinkProject>,
38 +) {
39 + const parsed = sourceControlClients.parseIssueUrl(url);
40 + if (parsed !== null || authority === null) return parsed;
41 + const hostname = new URL(url).hostname.toLowerCase();
42 + for (const project of projects) {
43 + const binding = projectIssueBinding(project);
44 + if (binding === null || (binding.host !== hostname && binding.host !== authority)) continue;
45 + const known = sourceControlClients.parseIssueUrl(url, project.repositoryIdentity?.provider);
46 + if (known !== null) return known;
47 + }
48 + return null;
49 +}
50 +
51 /**
52 * The reference an issue link resolves to, and the project it is read through: the project whose
53 * tracker binding is that host and scope, else any project on the same tracker and host lending
@@ -42,11 +60,11 @@ export function resolveIssueLinkTarget<Project extends LinkProject>(input: {
60 readonly projects: ReadonlyArray<Project>;
61 readonly preferredProjectId?: string | undefined;
62 }): { readonly project: Project; readonly ref: IssueRef } | null {
45 - const parsed = sourceControlClients.parseIssueUrl(input.url);
46 - if (parsed === null) return null;
47 - const { definition, link } = parsed;
63 // A link names its server's port; a binding does only when its remote or web URL did.
64 const authority = linkAuthority(input.url);
65 + const parsed = parseIssueLink(input.url, authority, input.projects);
66 + if (parsed === null) return null;
67 + const { definition, link } = parsed;
68 const onHost = input.projects.flatMap((project) => {
69 const binding = projectIssueBinding(project);
70 return binding === null ||
packages/source-control-core/src/shared/definition.ts
+11 -6
@@ -274,8 +274,11 @@ export interface SourceControlDefinition {
274 readonly parseCommitUrl?: (url: URL, known: boolean) => CommitLink | null;
275 /** Null when the URL is not one of this host's change requests. */
276 readonly parseChangeRequestUrl: (url: URL) => ParsedChangeRequestUrl | null;
277 - /** Null when the URL is not one of this host's issues. Absent for a host with none. */
278 - readonly parseIssueUrl?: (url: URL) => IssueLink | null;
277 + /**
278 + * Null when the URL is not one of this host's issues. Absent for a host with none. `known` is
279 + * set when the caller already knows this host serves the URL's repository.
280 + */
281 + readonly parseIssueUrl?: (url: URL, known: boolean) => IssueLink | null;
282 /**
283 * The repository URL when `url` is a page inside one of this host's repositories. `known` is set
284 * when the caller already knows this host serves the URL's repository. Off a known host, return
@@ -670,9 +673,10 @@ export interface SourceControlDefinitionRegistry {
673 readonly findByPublicDomain: (hostname: string) => SourceControlDefinition | undefined;
674 /** The first host, in registry order, that reads `url` as one of its change requests. */
675 readonly parseChangeRequestUrl: (url: string) => ParsedChangeRequest | null;
673 - /** The first host, in registry order, that reads `url` as one of its issues. */
676 + /** The first host, in registry order, that reads `url` as one of its issues, or `kind` alone. */
677 readonly parseIssueUrl: (
678 url: string,
679 + kind?: SourceControlProviderKind,
680 ) => { readonly definition: SourceControlDefinition; readonly link: IssueLink } | null;
681 readonly parseCommitUrl: (url: string, kind?: SourceControlProviderKind) => ParsedCommit | null;
682 readonly findByChangeRequestUrl: (url: string) => SourceControlDefinition | undefined;
@@ -792,11 +796,12 @@ export function makeSourceControlDefinitionRegistry(
796 );
797 },
798 parseChangeRequestUrl,
795 - parseIssueUrl: (value) => {
799 + parseIssueUrl: (value, kind) => {
800 const url = httpUrl(value);
801 if (url === null) return null;
798 - for (const definition of claimOrder) {
799 - const link = definition.parseIssueUrl?.(url) ?? null;
802 + const preferred = kind === undefined ? undefined : byKind.get(kind);
803 + for (const definition of kind === undefined ? claimOrder : preferred ? [preferred] : []) {
804 + const link = definition.parseIssueUrl?.(url, preferred !== undefined) ?? null;
805 if (link !== null) return { definition, link };
806 }
807 return null;
packages/source-control-github/src/server/GitHubSourceControlProvider.test.ts
+29
@@ -265,6 +265,35 @@ const githubContext = (host: string) => ({
265 });
266
267 describe("GitHubSourceControlProvider repository resolution", () => {
268 + // regression: #38251 an Enterprise Server's hostname need not say "github"; a gh login vouches for it
269 + it.effect.each([
270 + ["github", "github"],
271 + ["unknown", "unknown"],
272 + ] as const)("refines a remote on an unknown host the gh login reads as %s", ([seen, expected]) =>
273 + Effect.gen(function* () {
274 + const provider = yield* makeProvider({});
275 + const remoteUrl = "https://code.acme.test/acme/web.git";
276 + const identity = {
277 + canonicalKey: "code.acme.test/acme/web",
278 + locator: { source: "git-remote" as const, remoteName: "origin", remoteUrl },
279 + rootPath: "/repo",
280 + provider: SourceControlProviderKind.make("unknown"),
281 + };
282 + const refined = yield* provider.refineRepositoryIdentity!({
283 + identity,
284 + resolveContext: ({ context }) =>
285 + Effect.succeed({
286 + ...context,
287 + provider: { ...context.provider, kind: SourceControlProviderKind.make(seen) },
288 + }),
289 + });
290 + assert.deepStrictEqual(refined, {
291 + ...identity,
292 + provider: SourceControlProviderKind.make(expected),
293 + });
294 + }),
295 + );
296 +
297 it.effect("reads the repository gh would pick from the remotes", () => {
298 const paths: string[] = [];
299 const { layer } = harness({
packages/source-control-github/src/server/GitHubSourceControlProvider.ts
+30 -1
@@ -61,7 +61,11 @@ import {
61 type SourceControlManagedCliDiscoverySpec,
62 } from "@t3tools/source-control-core/server/discovery";
63 import * as SourceControlHost from "@t3tools/source-control-core/server/SourceControlHost";
64 -import { readSourceControlHostSettings } from "@t3tools/source-control-core/shared/definition";
64 +import {
65 + parseGitRemoteHost,
66 + readSourceControlHostSettings,
67 + unknownRemoteProvider,
68 +} from "@t3tools/source-control-core/shared/definition";
69
70 import * as GitHubClient from "../shared/definition.ts";
71 import {
@@ -339,6 +343,30 @@ class GitHubFailure extends Schema.TaggedError<GitHubFailure>()("GitHubFailure",
343
344 const failure = (detail: string, cause?: unknown) => new GitHubFailure({ detail, cause });
345
346 +// A gh login confirms a GitHub Enterprise Server whose hostname does not identify its provider.
347 +const refineRepositoryIdentity: NonNullable<
348 + SourceControlProvider.SourceControlProvider["Service"]["refineRepositoryIdentity"]
349 +> = Effect.fn("GitHubSourceControlProvider.refineRepositoryIdentity")(function* ({
350 + identity,
351 + resolveContext,
352 +}) {
353 + if (!identity.rootPath || (identity.provider !== undefined && identity.provider !== "unknown"))
354 + return identity;
355 + const remote = parseGitRemoteHost(identity.locator.remoteUrl);
356 + if (remote === null) return identity;
357 + const context = yield* resolveContext({
358 + cwd: identity.rootPath,
359 + context: {
360 + provider: unknownRemoteProvider(remote),
361 + remoteName: identity.locator.remoteName,
362 + remoteUrl: identity.locator.remoteUrl,
363 + },
364 + });
365 + return context?.provider.kind === "github"
366 + ? { ...identity, provider: SourceControlProviderKind.make("github") }
367 + : identity;
368 +});
369 +
370 const PULL_REQUEST_NOT_FOUND = "Pull request not found. Check the PR number or URL and try again.";
371 const REPOSITORY_NOT_FOUND = "Repository not found. Check the owner and name and try again.";
372
@@ -968,6 +996,7 @@ export const make = Effect.gen(function* () {
996
997 return SourceControlProvider.SourceControlProvider.of({
998 kind: SourceControlProviderKind.make("github"),
999 + refineRepositoryIdentity,
1000 resolveRemoteWebHost: Effect.fn("GitHubSourceControlProvider.resolveRemoteWebHost")(
1001 ({ context }) => Effect.succeed(gitHubApiHostForRemote(context.remoteUrl)),
1002 ),
packages/source-control-github/src/shared/definition.ts
+4 -2
@@ -101,8 +101,10 @@ export const definition = defineSourceControl({
101 parseCommitUrl: (url, known) =>
102 known || isGitHubHost(url.hostname) ? parseCommitPath(url, COMMIT_PATH) : null,
103 parseChangeRequestUrl: (url) => parseChangeRequestPath(url, CHANGE_REQUEST_PATH),
104 - // `/issues/` is too generic a path to believe from a host that is not GitHub's.
105 - parseIssueUrl: (url) => (isGitHubHost(url.hostname) ? parseIssuePath(url, ISSUE_PATH) : null),
104 + // `/issues/` is too generic a path to believe from a host that is not GitHub's, unless a known
105 + // project's host vouches for it as a GitHub Enterprise Server.
106 + parseIssueUrl: (url, known) =>
107 + known || isGitHubHost(url.hostname) ? parseIssuePath(url, ISSUE_PATH) : null,
108 repositoryUrlFromPage: (url) =>
109 isGitHubHost(url.hostname) ? repositoryUrlFromPagePath(url, REPOSITORY_PAGE_PATH) : null,
110 // GitHub writes every bare reference through `/issues/`, including pull requests.