@@ -20,7 +20,7 @@ import type { RemoteProvider } from './remoteProvider';
2020export type RemoteProviders = {
2121 custom : boolean ;
2222 matcher : string | RegExp ;
23- creator : ( container : Container , domain : string , path : string ) => RemoteProvider ;
23+ creator : ( container : Container , domain : string , path : string , scheme ?: string ) => RemoteProvider ;
2424} [ ] ;
2525
2626const builtInProviders : RemoteProviders = [
@@ -80,16 +80,26 @@ const builtInProviders: RemoteProviders = [
8080
8181const cloudProviderCreatorsMap : Record <
8282 CloudSelfHostedIntegrationId ,
83- ( container : Container , domain : string , path : string ) => RemoteProvider
83+ ( container : Container , domain : string , path : string , scheme : string | undefined ) => RemoteProvider
8484> = {
8585 [ SelfHostedIntegrationId . CloudGitHubEnterprise ] : ( container : Container , domain : string , path : string ) =>
8686 new GitHubRemote ( container , domain , path ) ,
8787 [ SelfHostedIntegrationId . CloudGitLabSelfHosted ] : ( container : Container , domain : string , path : string ) =>
8888 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 ) ) ,
9195} ;
9296
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+
93103export function loadRemoteProviders (
94104 cfg : RemotesConfig [ ] | null | undefined ,
95105 configuredIntegrations ?: ConfiguredIntegrationDescriptor [ ] ,
@@ -181,16 +191,16 @@ function getCustomProviderCreator(cfg: RemotesConfig) {
181191export async function getRemoteProviderMatcher (
182192 container : Container ,
183193 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 > {
185195 if ( providers == null ) {
186196 providers = loadRemoteProviders (
187197 configuration . get ( 'remotes' , null ) ,
188198 await container . integrations . getConfigured ( ) ,
189199 ) ;
190200 }
191201
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 ) ;
194204}
195205
196206function createBestRemoteProvider (
@@ -199,22 +209,27 @@ function createBestRemoteProvider(
199209 url : string ,
200210 domain : string ,
201211 path : string ,
212+ scheme : string | undefined ,
202213) : RemoteProvider | undefined {
203214 try {
204215 const key = domain . toLowerCase ( ) ;
205216 for ( const { custom, matcher, creator } of providers ) {
206217 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+ }
208221
209222 continue ;
210223 }
211224
212- if ( matcher . test ( key ) ) return creator ( container , domain , path ) ;
225+ if ( matcher . test ( key ) ) {
226+ return creator ( container , domain , path , scheme ) ;
227+ }
213228 if ( ! custom ) continue ;
214229
215230 const match = matcher . exec ( url ) ;
216231 if ( match != null ) {
217- return creator ( container , match [ 1 ] , match [ 2 ] ) ;
232+ return creator ( container , match [ 1 ] , match [ 2 ] , scheme ) ;
218233 }
219234 }
220235
0 commit comments