11import type { AuthenticationSessionsChangeEvent , CancellationToken , Event } from 'vscode' ;
22import { authentication , Disposable , env , EventEmitter , ProgressLocation , Uri , window } from 'vscode' ;
33import { isWeb } from '@env/platform' ;
4- import type { IntegrationId , SupportedCloudIntegrationIds } from '../../constants.integrations' ;
4+ import type {
5+ CloudSelfHostedIntegrationId ,
6+ IntegrationId ,
7+ SupportedCloudIntegrationIds ,
8+ } from '../../constants.integrations' ;
59import { HostingIntegrationId , IssueIntegrationId , SelfHostedIntegrationId } from '../../constants.integrations' ;
610import type { Source } from '../../constants.telemetry' ;
711import { sourceToContext } from '../../constants.telemetry' ;
@@ -38,12 +42,13 @@ import type {
3842 IntegrationType ,
3943 IssueIntegration ,
4044 ResourceDescriptor ,
45+ SupportedCloudSelfHostedIntegrationIds ,
4146 SupportedHostingIntegrationIds ,
4247 SupportedIntegrationIds ,
4348 SupportedIssueIntegrationIds ,
4449 SupportedSelfHostedIntegrationIds ,
4550} from './integration' ;
46- import { isHostingIntegrationId , isSelfHostedIntegrationId } from './providers/models' ;
51+ import { isCloudSelfHostedIntegrationId , isHostingIntegrationId , isSelfHostedIntegrationId } from './providers/models' ;
4752import type { ProvidersApi } from './providers/providersApi' ;
4853import { isGitHubDotCom , isGitLabDotCom } from './providers/utils' ;
4954
@@ -136,20 +141,22 @@ export class IntegrationService implements Disposable {
136141
137142 private async * getSupportedCloudIntegrations ( domainsById : Map < IntegrationId , string > ) : AsyncIterable < Integration > {
138143 for ( const id of getSupportedCloudIntegrationIds ( ) ) {
139- if (
140- ( id === SelfHostedIntegrationId . CloudGitHubEnterprise ||
141- id === SelfHostedIntegrationId . CloudGitLabSelfHosted ) &&
142- ! domainsById . has ( id )
143- ) {
144+ if ( isCloudSelfHostedIntegrationId ( id ) && ! domainsById . has ( id ) ) {
144145 try {
145146 // Try getting whatever we have now because we will need to disconnect
146- yield this . get ( id ) ;
147+ const integration = await this . get ( id , undefined ) ;
148+ if ( integration != null ) {
149+ yield integration ;
150+ }
147151 } catch {
148152 // Ignore this exception and continue,
149153 // because we probably haven't ever had an instance of this integration
150154 }
151155 } else {
152- yield this . get ( id , domainsById . get ( id ) ) ;
156+ const integration = await this . get ( id , domainsById . get ( id ) ) ;
157+ if ( integration != null ) {
158+ yield integration ;
159+ }
153160 }
154161 }
155162 }
@@ -245,6 +252,7 @@ export class IntegrationService implements Disposable {
245252 for ( const integrationId of integrationIds ) {
246253 try {
247254 const integration = await this . get ( integrationId ) ;
255+ if ( integration == null ) continue ;
248256 if ( integration . maybeConnected ?? ( await integration . isConnected ( ) ) ) {
249257 connectedIntegrations . add ( integrationId ) ;
250258 }
@@ -368,6 +376,7 @@ export class IntegrationService implements Disposable {
368376 if ( integrationIds != null ) {
369377 for ( const integrationId of integrationIds ) {
370378 const integration = await this . get ( integrationId ) ;
379+ if ( integration == null ) continue ;
371380 const connected = integration . maybeConnected ?? ( await integration . isConnected ( ) ) ;
372381 if ( connected && ! connectedIntegrations . has ( integrationId ) ) {
373382 return true ;
@@ -455,19 +464,18 @@ export class IntegrationService implements Disposable {
455464 return key == null ? this . _connectedCache . size !== 0 : this . _connectedCache . has ( key ) ;
456465 }
457466
458- get (
459- id :
460- | SupportedHostingIntegrationIds
461- | SelfHostedIntegrationId . CloudGitHubEnterprise
462- | SelfHostedIntegrationId . CloudGitLabSelfHosted ,
463- ) : Promise < HostingIntegration > ;
467+ get ( id : SupportedHostingIntegrationIds ) : Promise < HostingIntegration > ;
464468 get ( id : SupportedIssueIntegrationIds ) : Promise < IssueIntegration > ;
465- get ( id : SupportedSelfHostedIntegrationIds , domain : string ) : Promise < HostingIntegration > ;
466- get ( id : SupportedIntegrationIds , domain ?: string ) : Promise < Integration > ;
469+ get (
470+ id : SupportedHostingIntegrationIds | SupportedCloudSelfHostedIntegrationIds ,
471+ domain ?: string ,
472+ ) : Promise < HostingIntegration | undefined > ;
473+ get ( id : SupportedSelfHostedIntegrationIds , domain : string ) : Promise < HostingIntegration | undefined > ;
474+ get ( id : SupportedIntegrationIds , domain ?: string ) : Promise < Integration | undefined > ;
467475 async get (
468476 id : SupportedHostingIntegrationIds | SupportedIssueIntegrationIds | SupportedSelfHostedIntegrationIds ,
469477 domain ?: string ,
470- ) : Promise < Integration > {
478+ ) : Promise < Integration | undefined > {
471479 let integration = this . getCached ( id , domain ) ;
472480 if ( integration == null ) {
473481 switch ( id ) {
@@ -504,7 +512,7 @@ export class IntegrationService implements Disposable {
504512 break ;
505513 }
506514
507- throw new Error ( `Domain is required for ' ${ id } ' integration` ) ;
515+ return undefined ;
508516 }
509517
510518 integration = new (
@@ -562,7 +570,7 @@ export class IntegrationService implements Disposable {
562570 break ;
563571 }
564572
565- throw new Error ( `Domain is required for ' ${ id } ' integration` ) ;
573+ return undefined ;
566574 }
567575
568576 integration = new (
@@ -825,25 +833,9 @@ export class IntegrationService implements Disposable {
825833 args : { 0 : integrationIds => ( integrationIds ?. length ? integrationIds . join ( ',' ) : '<undefined>' ) } ,
826834 } )
827835 async getMyCurrentAccounts (
828- integrationIds : (
829- | HostingIntegrationId
830- | SelfHostedIntegrationId . CloudGitHubEnterprise
831- | SelfHostedIntegrationId . CloudGitLabSelfHosted
832- ) [ ] ,
833- ) : Promise <
834- Map <
835- | HostingIntegrationId
836- | SelfHostedIntegrationId . CloudGitHubEnterprise
837- | SelfHostedIntegrationId . CloudGitLabSelfHosted ,
838- Account
839- >
840- > {
841- const accounts = new Map <
842- | HostingIntegrationId
843- | SelfHostedIntegrationId . CloudGitHubEnterprise
844- | SelfHostedIntegrationId . CloudGitLabSelfHosted ,
845- Account
846- > ( ) ;
836+ integrationIds : ( HostingIntegrationId | CloudSelfHostedIntegrationId ) [ ] ,
837+ ) : Promise < Map < HostingIntegrationId | CloudSelfHostedIntegrationId , Account > > {
838+ const accounts = new Map < HostingIntegrationId | CloudSelfHostedIntegrationId , Account > ( ) ;
847839 await Promise . allSettled (
848840 integrationIds . map ( async integrationId => {
849841 const integration = await this . get ( integrationId ) ;
@@ -862,11 +854,7 @@ export class IntegrationService implements Disposable {
862854 args : { 0 : integrationIds => ( integrationIds ?. length ? integrationIds . join ( ',' ) : '<undefined>' ) , 1 : false } ,
863855 } )
864856 async getMyPullRequests (
865- integrationIds ?: (
866- | HostingIntegrationId
867- | SelfHostedIntegrationId . CloudGitHubEnterprise
868- | SelfHostedIntegrationId . CloudGitLabSelfHosted
869- ) [ ] ,
857+ integrationIds ?: ( HostingIntegrationId | CloudSelfHostedIntegrationId ) [ ] ,
870858 cancellation ?: CancellationToken ,
871859 silent ?: boolean ,
872860 ) : Promise < IntegrationResult < SearchedPullRequest [ ] | undefined > > {
0 commit comments