@@ -44,6 +44,7 @@ import type {
44
44
} from './integration' ;
45
45
import { isHostingIntegrationId , isSelfHostedIntegrationId } from './providers/models' ;
46
46
import type { ProvidersApi } from './providers/providersApi' ;
47
+ import { isGitHubDotCom } from './providers/utils' ;
47
48
48
49
export interface ConnectionStateChangeEvent {
49
50
key : string ;
@@ -88,8 +89,10 @@ export class IntegrationService implements Disposable {
88
89
@gate ( )
89
90
@debug ( )
90
91
private async syncCloudIntegrations ( forceConnect : boolean ) {
92
+ const scope = getLogScope ( ) ;
91
93
const connectedIntegrations = new Set < IntegrationId > ( ) ;
92
94
const loggedIn = await this . container . subscription . getAuthenticationSession ( ) ;
95
+ const domains = new Map < string , string > ( ) ;
93
96
if ( loggedIn ) {
94
97
const cloudIntegrations = await this . container . cloudIntegrations ;
95
98
const connections = await cloudIntegrations ?. getConnections ( ) ;
@@ -100,10 +103,18 @@ export class IntegrationService implements Disposable {
100
103
// GKDev includes some integrations like "google" that we don't support
101
104
if ( integrationId == null ) return ;
102
105
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
+ }
103
114
} ) ;
104
115
}
105
116
106
- for await ( const integration of this . getSupportedCloudIntegrations ( ) ) {
117
+ for await ( const integration of this . getSupportedCloudIntegrations ( domains ) ) {
107
118
await integration . syncCloudConnection (
108
119
connectedIntegrations . has ( integration . id ) ? 'connected' : 'disconnected' ,
109
120
forceConnect ,
@@ -121,9 +132,19 @@ export class IntegrationService implements Disposable {
121
132
return connectedIntegrations ;
122
133
}
123
134
124
- private async * getSupportedCloudIntegrations ( ) {
135
+ private async * getSupportedCloudIntegrations ( domains : Map < string , string > ) : AsyncIterable < Integration > {
125
136
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
+ }
127
148
}
128
149
}
129
150
@@ -437,6 +458,7 @@ export class IntegrationService implements Disposable {
437
458
await import ( /* webpackChunkName: "integrations" */ './providers/github' )
438
459
) . GitHubIntegration ( this . container , this . authenticationService , this . getProvidersApi . bind ( this ) ) ;
439
460
break ;
461
+ case SelfHostedIntegrationId . CloudGitHubEnterprise :
440
462
case SelfHostedIntegrationId . GitHubEnterprise :
441
463
if ( domain == null ) throw new Error ( `Domain is required for '${ id } ' integration` ) ;
442
464
integration = new (
@@ -446,6 +468,7 @@ export class IntegrationService implements Disposable {
446
468
this . authenticationService ,
447
469
this . getProvidersApi . bind ( this ) ,
448
470
domain ,
471
+ id ,
449
472
) ;
450
473
break ;
451
474
case HostingIntegrationId . GitLab :
@@ -549,6 +572,9 @@ export class IntegrationService implements Disposable {
549
572
if ( remote . provider . custom && remote . provider . domain != null ) {
550
573
return get ( SelfHostedIntegrationId . GitHubEnterprise , remote . provider . domain ) as RT ;
551
574
}
575
+ if ( remote . provider . domain != null && ! isGitHubDotCom ( remote . provider . domain ) ) {
576
+ return get ( SelfHostedIntegrationId . CloudGitHubEnterprise , remote . provider . domain ) as RT ;
577
+ }
552
578
return get ( HostingIntegrationId . GitHub ) as RT ;
553
579
case 'gitlab' :
554
580
if ( remote . provider . custom && remote . provider . domain != null ) {
0 commit comments