@@ -44,6 +44,7 @@ import type {
4444} from './integration' ;
4545import { isHostingIntegrationId , isSelfHostedIntegrationId } from './providers/models' ;
4646import type { ProvidersApi } from './providers/providersApi' ;
47+ import { isGitHubDotCom } from './providers/utils' ;
4748
4849export interface ConnectionStateChangeEvent {
4950 key : string ;
@@ -88,8 +89,10 @@ export class IntegrationService implements Disposable {
8889 @gate ( )
8990 @debug ( )
9091 private async syncCloudIntegrations ( forceConnect : boolean ) {
92+ const scope = getLogScope ( ) ;
9193 const connectedIntegrations = new Set < IntegrationId > ( ) ;
9294 const loggedIn = await this . container . subscription . getAuthenticationSession ( ) ;
95+ const domains = new Map < string , string > ( ) ;
9396 if ( loggedIn ) {
9497 const cloudIntegrations = await this . container . cloudIntegrations ;
9598 const connections = await cloudIntegrations ?. getConnections ( ) ;
@@ -100,10 +103,18 @@ export class IntegrationService implements Disposable {
100103 // GKDev includes some integrations like "google" that we don't support
101104 if ( integrationId == null ) return ;
102105 connectedIntegrations . add ( toIntegrationId [ p . provider ] ) ;
106+ if ( p . domain ?. length > 0 ) {
107+ try {
108+ const host = new URL ( p . domain ) . host ;
109+ domains . set ( integrationId , host ) ;
110+ } catch {
111+ Logger . warn ( `Invalid domain for ${ integrationId } integration: ${ p . domain } . Ignoring.` , scope ) ;
112+ }
113+ }
103114 } ) ;
104115 }
105116
106- for await ( const integration of this . getSupportedCloudIntegrations ( ) ) {
117+ for await ( const integration of this . getSupportedCloudIntegrations ( domains ) ) {
107118 await integration . syncCloudConnection (
108119 connectedIntegrations . has ( integration . id ) ? 'connected' : 'disconnected' ,
109120 forceConnect ,
@@ -121,9 +132,19 @@ export class IntegrationService implements Disposable {
121132 return connectedIntegrations ;
122133 }
123134
124- private async * getSupportedCloudIntegrations ( ) {
135+ private async * getSupportedCloudIntegrations ( domains : Map < string , string > ) : AsyncIterable < Integration > {
125136 for ( const id of getSupportedCloudIntegrationIds ( ) ) {
126- yield this . get ( id ) ;
137+ if ( id === SelfHostedIntegrationId . CloudGitHubEnterprise && ! domains . has ( id ) ) {
138+ try {
139+ // Try getting whatever we have now because we will need to disconnect
140+ yield this . get ( id ) ;
141+ } catch {
142+ // Ignore this exception and continue,
143+ // because we probably haven't ever had an instance of this integration
144+ }
145+ } else {
146+ yield this . get ( id , domains ?. get ( id ) ) ;
147+ }
127148 }
128149 }
129150
@@ -437,6 +458,7 @@ export class IntegrationService implements Disposable {
437458 await import ( /* webpackChunkName: "integrations" */ './providers/github' )
438459 ) . GitHubIntegration ( this . container , this . authenticationService , this . getProvidersApi . bind ( this ) ) ;
439460 break ;
461+ case SelfHostedIntegrationId . CloudGitHubEnterprise :
440462 case SelfHostedIntegrationId . GitHubEnterprise :
441463 if ( domain == null ) throw new Error ( `Domain is required for '${ id } ' integration` ) ;
442464 integration = new (
@@ -446,6 +468,7 @@ export class IntegrationService implements Disposable {
446468 this . authenticationService ,
447469 this . getProvidersApi . bind ( this ) ,
448470 domain ,
471+ id ,
449472 ) ;
450473 break ;
451474 case HostingIntegrationId . GitLab :
@@ -549,6 +572,9 @@ export class IntegrationService implements Disposable {
549572 if ( remote . provider . custom && remote . provider . domain != null ) {
550573 return get ( SelfHostedIntegrationId . GitHubEnterprise , remote . provider . domain ) as RT ;
551574 }
575+ if ( remote . provider . domain != null && ! isGitHubDotCom ( remote . provider . domain ) ) {
576+ return get ( SelfHostedIntegrationId . CloudGitHubEnterprise , remote . provider . domain ) as RT ;
577+ }
552578 return get ( HostingIntegrationId . GitHub ) as RT ;
553579 case 'gitlab' :
554580 if ( remote . provider . custom && remote . provider . domain != null ) {
0 commit comments