1
1
import type { RemotesConfig } from '../../config' ;
2
+ import { SelfHostedIntegrationId } from '../../constants.integrations' ;
2
3
import type { Container } from '../../container' ;
4
+ import type { CloudIntegrationConnection } from '../../plus/integrations/authentication/models' ;
5
+ import { toIntegrationId } from '../../plus/integrations/authentication/models' ;
3
6
import { Logger } from '../../system/logger' ;
4
7
import { configuration } from '../../system/vscode/configuration' ;
5
8
import { AzureDevOpsRemote } from './azure-devops' ;
@@ -73,7 +76,10 @@ const builtInProviders: RemoteProviders = [
73
76
} ,
74
77
] ;
75
78
76
- export function loadRemoteProviders ( cfg : RemotesConfig [ ] | null | undefined ) : RemoteProviders {
79
+ export function loadRemoteProviders (
80
+ cfg : RemotesConfig [ ] | null | undefined ,
81
+ connectedIntegrations : CloudIntegrationConnection [ ] | undefined ,
82
+ ) : RemoteProviders {
77
83
const providers : RemoteProviders = [ ] ;
78
84
79
85
if ( cfg ?. length ) {
@@ -97,6 +103,29 @@ export function loadRemoteProviders(cfg: RemotesConfig[] | null | undefined): Re
97
103
}
98
104
}
99
105
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
+
100
129
providers . push ( ...builtInProviders ) ;
101
130
102
131
return providers ;
@@ -136,12 +165,14 @@ function getCustomProviderCreator(cfg: RemotesConfig) {
136
165
}
137
166
}
138
167
139
- export function getRemoteProviderMatcher (
168
+ export async function getRemoteProviderMatcher (
140
169
container : Container ,
141
170
providers ?: RemoteProviders ,
142
- ) : ( url : string , domain : string , path : string ) => RemoteProvider | undefined {
171
+ ) : Promise < ( url : string , domain : string , path : string ) => RemoteProvider | undefined > {
143
172
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 ) ;
145
176
}
146
177
147
178
return ( url : string , domain : string , path : string ) =>
0 commit comments