diff --git a/packages/source-control-github/src/server/GitHubSourceControlProvider.ts b/packages/source-control-github/src/server/GitHubSourceControlProvider.ts index 4abb3d8d6669f..9818a6b776edb 100644 --- a/packages/source-control-github/src/server/GitHubSourceControlProvider.ts +++ b/packages/source-control-github/src/server/GitHubSourceControlProvider.ts @@ -308,8 +308,9 @@ export const makeDiscovery = Effect.gen(function* () { refineUnknownRemote: ({ context }) => { const url = URL.parse(context.provider.baseUrl); if (!url?.host) return Effect.succeed(null); + const host = gitHubApiHostForRemote(context.remoteUrl) ?? url.host; // A timeout or keyring failure propagates: the registry does not keep that answer. - return api.credential(url.host).pipe( + return api.credential(host).pipe( Effect.as(true), Effect.catchTags({ GitHubCliMissingError: () => Effect.succeed(false), @@ -320,8 +321,8 @@ export const makeDiscovery = Effect.gen(function* () { known ? ({ kind: SourceControlProviderKind.make("github"), - name: "GitHub Self-Hosted", - baseUrl: context.provider.baseUrl, + name: host === "github.com" ? "GitHub" : "GitHub Self-Hosted", + baseUrl: host === url.host ? context.provider.baseUrl : `https://${host}`, } as const) : null, ), diff --git a/packages/source-control-github/src/server/gitHubDiscovery.test.ts b/packages/source-control-github/src/server/gitHubDiscovery.test.ts index c1f4304f4b04b..3c34ddd05bb84 100644 --- a/packages/source-control-github/src/server/gitHubDiscovery.test.ts +++ b/packages/source-control-github/src/server/gitHubDiscovery.test.ts @@ -84,6 +84,31 @@ it.effect("asks for no credential when the identity resolver left the base URL e }), ); +it.effect.each([ + ["github-work", "git@github-work:team/project.git"], + ["github-ci", "git@github-ci:team/project.git"], + ["github-work", "ssh://git@github-work:22/team/project.git"], + ["github.com-work", "git@github.com-work:team/project.git"], +] as const)("recognizes a GitHub SSH alias on %s (%s)", ([host, remoteUrl]) => + Effect.gen(function* () { + const discovery = yield* makeDiscovery((host) => + host === "github.com" + ? Effect.succeed({ token: Redacted.make("token"), fingerprint: `${host}:fingerprint` }) + : Effect.fail(new GitHubCredentials.GitHubNotSignedInError({ host })), + ); + if (discovery.type !== "managed-cli") return assert.fail("expected a managed CLI"); + const provider = yield* discovery.refineUnknownRemote({ + cwd: "/repo", + context: { ...unknownContext(`https://${host}`), remoteUrl }, + }); + assert.deepStrictEqual(provider, { + kind: SourceControlProviderKind.make("github"), + name: "GitHub", + baseUrl: "https://github.com", + }); + }), +); + const decodeSettings = Schema.decodeSync(ServerSettings); const referencedTokenSettings = decodeSettings({ sourceControlHosts: {