@@ -45,7 +45,7 @@ import type {
4545} from './integration' ;
4646import { isHostingIntegrationId , isSelfHostedIntegrationId } from './providers/models' ;
4747import type { ProvidersApi } from './providers/providersApi' ;
48- import { isGitHubDotCom } from './providers/utils' ;
48+ import { isGitHubDotCom , isGitLabDotCom } from './providers/utils' ;
4949
5050export interface ConnectionStateChangeEvent {
5151 key : string ;
@@ -136,7 +136,11 @@ export class IntegrationService implements Disposable {
136136
137137 private async * getSupportedCloudIntegrations ( domainsById : Map < IntegrationId , string > ) : AsyncIterable < Integration > {
138138 for ( const id of getSupportedCloudIntegrationIds ( ) ) {
139- if ( id === SelfHostedIntegrationId . CloudGitHubEnterprise && ! domainsById . has ( id ) ) {
139+ if (
140+ ( id === SelfHostedIntegrationId . CloudGitHubEnterprise ||
141+ id === SelfHostedIntegrationId . CloudGitLabSelfHosted ) &&
142+ ! domainsById . has ( id )
143+ ) {
140144 try {
141145 // Try getting whatever we have now because we will need to disconnect
142146 yield this . get ( id ) ;
@@ -452,7 +456,10 @@ export class IntegrationService implements Disposable {
452456 }
453457
454458 get (
455- id : SupportedHostingIntegrationIds | SelfHostedIntegrationId . CloudGitHubEnterprise ,
459+ id :
460+ | SupportedHostingIntegrationIds
461+ | SelfHostedIntegrationId . CloudGitHubEnterprise
462+ | SelfHostedIntegrationId . CloudGitLabSelfHosted ,
456463 ) : Promise < HostingIntegration > ;
457464 get ( id : SupportedIssueIntegrationIds ) : Promise < IssueIntegration > ;
458465 get ( id : SupportedSelfHostedIntegrationIds , domain : string ) : Promise < HostingIntegration > ;
@@ -527,6 +534,47 @@ export class IntegrationService implements Disposable {
527534 await import ( /* webpackChunkName: "integrations" */ './providers/gitlab' )
528535 ) . GitLabIntegration ( this . container , this . authenticationService , this . getProvidersApi . bind ( this ) ) ;
529536 break ;
537+ case SelfHostedIntegrationId . CloudGitLabSelfHosted :
538+ if ( domain == null ) {
539+ integration = this . findCachedById ( id ) ;
540+ if ( integration != null ) {
541+ // return immediately in order to not to cache it after the "switch" block:
542+ return integration ;
543+ }
544+
545+ const existingConfigured = this . authenticationService . configured ?. get (
546+ SelfHostedIntegrationId . CloudGitLabSelfHosted ,
547+ ) ;
548+ if ( existingConfigured ?. length ) {
549+ const { domain : configuredDomain } = existingConfigured [ 0 ] ;
550+ if ( configuredDomain == null ) throw new Error ( `Domain is required for '${ id } ' integration` ) ;
551+ integration = new (
552+ await import ( /* webpackChunkName: "integrations" */ './providers/gitlab' )
553+ ) . GitLabSelfHostedIntegration (
554+ this . container ,
555+ this . authenticationService ,
556+ this . getProvidersApi . bind ( this ) ,
557+ configuredDomain ,
558+ id ,
559+ ) ;
560+ // assign domain because it's part of caching key:
561+ domain = configuredDomain ;
562+ break ;
563+ }
564+
565+ throw new Error ( `Domain is required for '${ id } ' integration` ) ;
566+ }
567+
568+ integration = new (
569+ await import ( /* webpackChunkName: "integrations" */ './providers/gitlab' )
570+ ) . GitLabSelfHostedIntegration (
571+ this . container ,
572+ this . authenticationService ,
573+ this . getProvidersApi . bind ( this ) ,
574+ domain ,
575+ id ,
576+ ) ;
577+ break ;
530578 case SelfHostedIntegrationId . GitLabSelfHosted :
531579 if ( domain == null ) throw new Error ( `Domain is required for '${ id } ' integration` ) ;
532580 integration = new (
@@ -536,6 +584,7 @@ export class IntegrationService implements Disposable {
536584 this . authenticationService ,
537585 this . getProvidersApi . bind ( this ) ,
538586 domain ,
587+ id ,
539588 ) ;
540589 break ;
541590 case HostingIntegrationId . Bitbucket :
@@ -630,8 +679,13 @@ export class IntegrationService implements Disposable {
630679 }
631680 return get ( HostingIntegrationId . GitHub ) as RT ;
632681 case 'gitlab' :
633- if ( remote . provider . custom && remote . provider . domain != null ) {
634- return get ( SelfHostedIntegrationId . GitLabSelfHosted , remote . provider . domain ) as RT ;
682+ if ( remote . provider . domain != null && ! isGitLabDotCom ( remote . provider . domain ) ) {
683+ return get (
684+ remote . provider . custom
685+ ? SelfHostedIntegrationId . GitLabSelfHosted
686+ : SelfHostedIntegrationId . CloudGitLabSelfHosted ,
687+ remote . provider . domain ,
688+ ) as RT ;
635689 }
636690 return get ( HostingIntegrationId . GitLab ) as RT ;
637691 default :
@@ -771,9 +825,25 @@ export class IntegrationService implements Disposable {
771825 args : { 0 : integrationIds => ( integrationIds ?. length ? integrationIds . join ( ',' ) : '<undefined>' ) } ,
772826 } )
773827 async getMyCurrentAccounts (
774- integrationIds : ( HostingIntegrationId | SelfHostedIntegrationId . CloudGitHubEnterprise ) [ ] ,
775- ) : Promise < Map < HostingIntegrationId | SelfHostedIntegrationId . CloudGitHubEnterprise , Account > > {
776- const accounts = new Map < HostingIntegrationId | SelfHostedIntegrationId . CloudGitHubEnterprise , Account > ( ) ;
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+ > ( ) ;
777847 await Promise . allSettled (
778848 integrationIds . map ( async integrationId => {
779849 const integration = await this . get ( integrationId ) ;
@@ -792,7 +862,11 @@ export class IntegrationService implements Disposable {
792862 args : { 0 : integrationIds => ( integrationIds ?. length ? integrationIds . join ( ',' ) : '<undefined>' ) , 1 : false } ,
793863 } )
794864 async getMyPullRequests (
795- integrationIds ?: ( HostingIntegrationId | SelfHostedIntegrationId . CloudGitHubEnterprise ) [ ] ,
865+ integrationIds ?: (
866+ | HostingIntegrationId
867+ | SelfHostedIntegrationId . CloudGitHubEnterprise
868+ | SelfHostedIntegrationId . CloudGitLabSelfHosted
869+ ) [ ] ,
796870 cancellation ?: CancellationToken ,
797871 silent ?: boolean ,
798872 ) : Promise < IntegrationResult < SearchedPullRequest [ ] | undefined > > {
0 commit comments