11import type { RemotesConfig } from '../../config' ;
2+ import { SelfHostedIntegrationId } from '../../constants.integrations' ;
23import type { Container } from '../../container' ;
4+ import type { CloudIntegrationConnection } from '../../plus/integrations/authentication/models' ;
5+ import { toIntegrationId } from '../../plus/integrations/authentication/models' ;
36import { Logger } from '../../system/logger' ;
47import { configuration } from '../../system/vscode/configuration' ;
58import { AzureDevOpsRemote } from './azure-devops' ;
@@ -73,7 +76,10 @@ const builtInProviders: RemoteProviders = [
7376 } ,
7477] ;
7578
76- export function loadRemoteProviders ( cfg : RemotesConfig [ ] | null | undefined ) : RemoteProviders {
79+ export function loadRemoteProviders (
80+ cfg : RemotesConfig [ ] | null | undefined ,
81+ connectedIntegrations : CloudIntegrationConnection [ ] | undefined ,
82+ ) : RemoteProviders {
7783 const providers : RemoteProviders = [ ] ;
7884
7985 if ( cfg ?. length ) {
@@ -97,6 +103,29 @@ export function loadRemoteProviders(cfg: RemotesConfig[] | null | undefined): Re
97103 }
98104 }
99105
106+ if ( connectedIntegrations ?. length ) {
107+ for ( const ci of connectedIntegrations ) {
108+ if ( toIntegrationId [ ci . provider ] === SelfHostedIntegrationId . CloudGitHubEnterprise ) {
109+ const matcher = new URL ( ci . domain ) . host . toLocaleLowerCase ( ) ;
110+ const providerCreator = ( _container : Container , domain : string , path : string ) =>
111+ new GitHubRemote ( domain , path ) ;
112+ const provider = {
113+ custom : false ,
114+ matcher : matcher ,
115+ creator : providerCreator ,
116+ } ;
117+
118+ const indexOfCustomDuplication : number = providers . findIndex ( p => p . matcher === matcher ) ;
119+
120+ if ( indexOfCustomDuplication !== - 1 ) {
121+ providers [ indexOfCustomDuplication ] = provider ;
122+ } else {
123+ providers . push ( provider ) ;
124+ }
125+ }
126+ }
127+ }
128+
100129 providers . push ( ...builtInProviders ) ;
101130
102131 return providers ;
@@ -136,12 +165,14 @@ function getCustomProviderCreator(cfg: RemotesConfig) {
136165 }
137166}
138167
139- export function getRemoteProviderMatcher (
168+ export async function getRemoteProviderMatcher (
140169 container : Container ,
141170 providers ?: RemoteProviders ,
142- ) : ( url : string , domain : string , path : string ) => RemoteProvider | undefined {
171+ ) : Promise < ( url : string , domain : string , path : string ) => RemoteProvider | undefined > {
143172 if ( providers == null ) {
144- providers = loadRemoteProviders ( configuration . get ( 'remotes' , null ) ) ;
173+ const ci = await container . cloudIntegrations ;
174+ const c = await ci ?. getConnections ( ) ;
175+ providers = loadRemoteProviders ( configuration . get ( 'remotes' , null ) , c ) ;
145176 }
146177
147178 return ( url : string , domain : string , path : string ) =>
0 commit comments