@@ -20,7 +20,7 @@ import type { RemoteProvider } from './remoteProvider';
20
20
export type RemoteProviders = {
21
21
custom : boolean ;
22
22
matcher : string | RegExp ;
23
- creator : ( container : Container , domain : string , path : string ) => RemoteProvider ;
23
+ creator : ( container : Container , domain : string , path : string , scheme ?: string ) => RemoteProvider ;
24
24
} [ ] ;
25
25
26
26
const builtInProviders : RemoteProviders = [
@@ -80,16 +80,26 @@ const builtInProviders: RemoteProviders = [
80
80
81
81
const cloudProviderCreatorsMap : Record <
82
82
CloudSelfHostedIntegrationId ,
83
- ( container : Container , domain : string , path : string ) => RemoteProvider
83
+ ( container : Container , domain : string , path : string , scheme : string | undefined ) => RemoteProvider
84
84
> = {
85
85
[ SelfHostedIntegrationId . CloudGitHubEnterprise ] : ( container : Container , domain : string , path : string ) =>
86
86
new GitHubRemote ( container , domain , path ) ,
87
87
[ SelfHostedIntegrationId . CloudGitLabSelfHosted ] : ( container : Container , domain : string , path : string ) =>
88
88
new GitLabRemote ( container , domain , path ) ,
89
- [ SelfHostedIntegrationId . BitbucketServer ] : ( container : Container , domain : string , path : string ) =>
90
- new BitbucketServerRemote ( container , domain , path ) ,
89
+ [ SelfHostedIntegrationId . BitbucketServer ] : (
90
+ container : Container ,
91
+ domain : string ,
92
+ path : string ,
93
+ scheme : string | undefined ,
94
+ ) => new BitbucketServerRemote ( container , domain , path , cleanProtocol ( scheme ) ) ,
91
95
} ;
92
96
97
+ const dirtyProtocolPattern = / ( \w + ) \W * / ;
98
+ function cleanProtocol ( scheme : string | undefined ) : string | undefined {
99
+ const match = scheme ?. match ( dirtyProtocolPattern ) ;
100
+ return match ?. [ 1 ] ?? undefined ;
101
+ }
102
+
93
103
export function loadRemoteProviders (
94
104
cfg : RemotesConfig [ ] | null | undefined ,
95
105
configuredIntegrations ?: ConfiguredIntegrationDescriptor [ ] ,
@@ -181,16 +191,16 @@ function getCustomProviderCreator(cfg: RemotesConfig) {
181
191
export async function getRemoteProviderMatcher (
182
192
container : Container ,
183
193
providers ?: RemoteProviders ,
184
- ) : Promise < ( url : string , domain : string , path : string ) => RemoteProvider | undefined > {
194
+ ) : Promise < ( url : string , domain : string , path : string , sheme : string | undefined ) => RemoteProvider | undefined > {
185
195
if ( providers == null ) {
186
196
providers = loadRemoteProviders (
187
197
configuration . get ( 'remotes' , null ) ,
188
198
await container . integrations . getConfigured ( ) ,
189
199
) ;
190
200
}
191
201
192
- return ( url : string , domain : string , path : string ) =>
193
- createBestRemoteProvider ( container , providers , url , domain , path ) ;
202
+ return ( url : string , domain : string , path : string , scheme ) =>
203
+ createBestRemoteProvider ( container , providers , url , domain , path , scheme ) ;
194
204
}
195
205
196
206
function createBestRemoteProvider (
@@ -199,22 +209,27 @@ function createBestRemoteProvider(
199
209
url : string ,
200
210
domain : string ,
201
211
path : string ,
212
+ scheme : string | undefined ,
202
213
) : RemoteProvider | undefined {
203
214
try {
204
215
const key = domain . toLowerCase ( ) ;
205
216
for ( const { custom, matcher, creator } of providers ) {
206
217
if ( typeof matcher === 'string' ) {
207
- if ( matcher === key ) return creator ( container , domain , path ) ;
218
+ if ( matcher === key ) {
219
+ return creator ( container , domain , path , scheme ) ;
220
+ }
208
221
209
222
continue ;
210
223
}
211
224
212
- if ( matcher . test ( key ) ) return creator ( container , domain , path ) ;
225
+ if ( matcher . test ( key ) ) {
226
+ return creator ( container , domain , path , scheme ) ;
227
+ }
213
228
if ( ! custom ) continue ;
214
229
215
230
const match = matcher . exec ( url ) ;
216
231
if ( match != null ) {
217
- return creator ( container , match [ 1 ] , match [ 2 ] ) ;
232
+ return creator ( container , match [ 1 ] , match [ 2 ] , scheme ) ;
218
233
}
219
234
}
220
235
0 commit comments