Skip to content

Commit 6e3eed5

Browse files
authored
When authority is ghe.com, don't probe API to determine if enterprise (#6246)
Fixes #6233
1 parent 1066de6 commit 6e3eed5

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

src/authentication/githubServer.ts

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,9 @@ import { HostHelper } from './configuration';
1313

1414
export class GitHubManager {
1515
private static readonly _githubDotComServers = new Set<string>().add('github.com').add('ssh.github.com');
16+
private static readonly _gheServers = new Set<string>().add('ghe.com');
1617
private static readonly _neverGitHubServers = new Set<string>().add('bitbucket.org').add('gitlab.com');
17-
private _servers: Map<string, GitHubServerType> = new Map(Array.from(GitHubManager._githubDotComServers.keys()).map(key => [key, GitHubServerType.GitHubDotCom]));
18+
private _knownServers: Map<string, GitHubServerType> = new Map([...Array.from(GitHubManager._githubDotComServers.keys()).map(key => [key, GitHubServerType.GitHubDotCom]), ...Array.from(GitHubManager._gheServers.keys()).map(key => [key, GitHubServerType.Enterprise])] as [string, GitHubServerType][]);
1819

1920
public static isGithubDotCom(host: string): boolean {
2021
return this._githubDotComServers.has(host);
@@ -28,23 +29,26 @@ export class GitHubManager {
2829
if (host === null) {
2930
return GitHubServerType.None;
3031
}
32+
const authority = host.authority.toLowerCase();
3133

3234
// .wiki/.git repos are not supported
33-
if (host.path.endsWith('.wiki') || host.authority.match(/gist[.]github[.]com/)) {
35+
if (host.path.endsWith('.wiki') || authority.match(/gist[.]github[.]com/)) {
3436
return GitHubServerType.None;
3537
}
3638

37-
if (GitHubManager.isGithubDotCom(host.authority)) {
39+
if (GitHubManager.isGithubDotCom(authority)) {
3840
return GitHubServerType.GitHubDotCom;
3941
}
4042

43+
const matchingKnownServer = Array.from(this._knownServers.keys()).find(server => authority.endsWith(server));
44+
4145
const knownEnterprise = getEnterpriseUri();
42-
if ((host.authority.toLowerCase() === knownEnterprise?.authority.toLowerCase()) && (!this._servers.has(host.authority) || (this._servers.get(host.authority) === GitHubServerType.None))) {
46+
if ((host.authority.toLowerCase() === knownEnterprise?.authority.toLowerCase()) && (!matchingKnownServer || (this._knownServers.get(matchingKnownServer) === GitHubServerType.None))) {
4347
return GitHubServerType.Enterprise;
4448
}
4549

46-
if (this._servers.has(host.authority)) {
47-
return this._servers.get(host.authority) ?? GitHubServerType.None;
50+
if (matchingKnownServer) {
51+
return this._knownServers.get(matchingKnownServer) ?? GitHubServerType.None;
4852
}
4953

5054
const [uri, options] = await GitHubManager.getOptions(host, 'HEAD', '/rate_limit');
@@ -85,7 +89,7 @@ export class GitHubManager {
8589
return isGitHub;
8690
} finally {
8791
Logger.debug(`Host ${host} is associated with GitHub: ${isGitHub}`, 'GitHubServer');
88-
this._servers.set(host.authority, isGitHub);
92+
this._knownServers.set(authority, isGitHub);
8993
}
9094
}
9195

0 commit comments

Comments
 (0)