Skip to content

Commit

Permalink
Makes sure that cloud version of GitHubEnterprise is used when needed
Browse files Browse the repository at this point in the history
  • Loading branch information
sergeibbb committed Jan 13, 2025
1 parent c7d5292 commit f00ba5b
Showing 1 changed file with 38 additions and 3 deletions.
41 changes: 38 additions & 3 deletions src/plus/integrations/integrationService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -237,9 +237,16 @@ export class IntegrationService implements Disposable {
}

for (const integrationId of integrationIds) {
const integration = await this.get(integrationId);
if (integration.maybeConnected ?? (await integration.isConnected())) {
connectedIntegrations.add(integrationId);
try {
const integration = await this.get(integrationId);
if (integration.maybeConnected ?? (await integration.isConnected())) {
connectedIntegrations.add(integrationId);
}
} catch (ex) {
Logger.log(
`Failed to get integration ${integrationId} by its ID. Consider it as not-connected and ignore. Error message: ${ex.message}`,
scope,
);
}
}

Expand Down Expand Up @@ -459,6 +466,24 @@ export class IntegrationService implements Disposable {
).GitHubIntegration(this.container, this.authenticationService, this.getProvidersApi.bind(this));
break;
case SelfHostedIntegrationId.CloudGitHubEnterprise:
if (domain == null) {
integration = this.findCachedById(id);
if (integration != null) {
// return immediately in order to not to cache it after the "switch" block:
return integration;
}
throw new Error(`Domain is required for '${id}' integration`);
}
integration = new (
await import(/* webpackChunkName: "integrations" */ './providers/github')
).GitHubEnterpriseIntegration(
this.container,
this.authenticationService,
this.getProvidersApi.bind(this),
domain,
id,
);
break;
case SelfHostedIntegrationId.GitHubEnterprise:
if (domain == null) throw new Error(`Domain is required for '${id}' integration`);
integration = new (
Expand Down Expand Up @@ -883,6 +908,16 @@ export class IntegrationService implements Disposable {
return this._integrations.get(this.getCacheKey(id, domain));
}

private findCachedById(id: SupportedSelfHostedIntegrationIds): Integration | undefined {
const key = this.getCacheKey(id, '');
for (const [k, integration] of this._integrations) {
if (k.startsWith(key)) {
return integration;
}
}
return undefined;
}

private getCacheKey(
id: SupportedHostingIntegrationIds | SupportedIssueIntegrationIds | SupportedSelfHostedIntegrationIds,
domain?: string,
Expand Down

0 comments on commit f00ba5b

Please sign in to comment.