Skip to content

Commit 45589ac

Browse files
committed
fix(github): find pull requests for SSH aliases
1 parent af65a55 commit 45589ac

2 files changed

Lines changed: 29 additions & 3 deletions

File tree

‎packages/source-control-github/src/server/GitHubSourceControlProvider.ts‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -308,8 +308,9 @@ export const makeDiscovery = Effect.gen(function* () {
308308
refineUnknownRemote: ({ context }) => {
309309
const url = URL.parse(context.provider.baseUrl);
310310
if (!url?.host) return Effect.succeed(null);
311+
const host = gitHubApiHostForRemote(context.remoteUrl) ?? url.host;
311312
// A timeout or keyring failure propagates: the registry does not keep that answer.
312-
return api.credential(url.host).pipe(
313+
return api.credential(host).pipe(
313314
Effect.as(true),
314315
Effect.catchTags({
315316
GitHubCliMissingError: () => Effect.succeed(false),
@@ -320,8 +321,8 @@ export const makeDiscovery = Effect.gen(function* () {
320321
known
321322
? ({
322323
kind: SourceControlProviderKind.make("github"),
323-
name: "GitHub Self-Hosted",
324-
baseUrl: context.provider.baseUrl,
324+
name: host === "github.com" ? "GitHub" : "GitHub Self-Hosted",
325+
baseUrl: host === url.host ? context.provider.baseUrl : `https://${host}`,
325326
} as const)
326327
: null,
327328
),

‎packages/source-control-github/src/server/gitHubDiscovery.test.ts‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,31 @@ it.effect("asks for no credential when the identity resolver left the base URL e
8484
}),
8585
);
8686

87+
it.effect.each([
88+
["github-work", "git@github-work:team/project.git"],
89+
["github-ci", "git@github-ci:team/project.git"],
90+
["github-work", "ssh://git@github-work:22/team/project.git"],
91+
["github.com-work", "[email protected]:team/project.git"],
92+
] as const)("recognizes a GitHub SSH alias on %s (%s)", ([host, remoteUrl]) =>
93+
Effect.gen(function* () {
94+
const discovery = yield* makeDiscovery((host) =>
95+
host === "github.com"
96+
? Effect.succeed({ token: Redacted.make("token"), fingerprint: `${host}:fingerprint` })
97+
: Effect.fail(new GitHubCredentials.GitHubNotSignedInError({ host })),
98+
);
99+
if (discovery.type !== "managed-cli") return assert.fail("expected a managed CLI");
100+
const provider = yield* discovery.refineUnknownRemote({
101+
cwd: "/repo",
102+
context: { ...unknownContext(`https://${host}`), remoteUrl },
103+
});
104+
assert.deepStrictEqual(provider, {
105+
kind: SourceControlProviderKind.make("github"),
106+
name: "GitHub",
107+
baseUrl: "https://github.com",
108+
});
109+
}),
110+
);
111+
87112
const decodeSettings = Schema.decodeSync(ServerSettings);
88113
const referencedTokenSettings = decodeSettings({
89114
sourceControlHosts: {

0 commit comments

Comments
 (0)