Skip to content

Commit 25559f5

Browse files
committed
Fix passing HTTP or HTTPS protocol to Bitbucket DataCenter provider
(#4184, #4107)
1 parent bf71603 commit 25559f5

File tree

4 files changed

+31
-15
lines changed

4 files changed

+31
-15
lines changed

src/git/parsers/remoteParser.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -52,15 +52,15 @@ export function parseGitRemotes(
5252
scheme,
5353
domain,
5454
path,
55-
remoteProviderMatcher(url, domain, path),
55+
remoteProviderMatcher(url, domain, path, scheme),
5656
[{ url: url, type: type as GitRemoteType }],
5757
);
5858
remotes.set(name, remote);
5959
} else {
6060
remote.urls.push({ url: url, type: type as GitRemoteType });
6161
if (remote.provider != null && type !== 'push') continue;
6262

63-
const provider = remoteProviderMatcher(url, domain, path);
63+
const provider = remoteProviderMatcher(url, domain, path, scheme);
6464
if (provider == null) continue;
6565

6666
remote = new GitRemote(container, repoPath, name, scheme, domain, path, provider, remote.urls);

src/git/remotes/remoteProviders.ts

+25-10
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import type { RemoteProvider } from './remoteProvider';
2020
export 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

2626
const builtInProviders: RemoteProviders = [
@@ -80,16 +80,26 @@ const builtInProviders: RemoteProviders = [
8080

8181
const 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+
93103
export function loadRemoteProviders(
94104
cfg: RemotesConfig[] | null | undefined,
95105
configuredIntegrations?: ConfiguredIntegrationDescriptor[],
@@ -181,16 +191,16 @@ function getCustomProviderCreator(cfg: RemotesConfig) {
181191
export 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

196206
function 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

src/plus/drafts/draftsService.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -725,7 +725,7 @@ export class DraftService implements Disposable {
725725
name = data.provider.repoName;
726726
} else if (data.remote?.url != null && data.remote?.domain != null && data.remote?.path != null) {
727727
const matcher = await getRemoteProviderMatcher(this.container);
728-
const provider = matcher(data.remote.url, data.remote.domain, data.remote.path);
728+
const provider = matcher(data.remote.url, data.remote.domain, data.remote.path, undefined);
729729
name = provider?.repoName ?? data.remote.path;
730730
} else {
731731
name =

src/plus/integrations/providers/github/sub-providers/remotes.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ export class RemotesGitSubProvider extends RemotesGitProviderBase {
1919
const [, owner, repo] = uri.path.split('/', 3);
2020

2121
const url = `https://github.com/${owner}/${repo}.git`;
22+
const protocol = 'https';
2223
const domain = 'github.com';
2324
const path = `${owner}/${repo}`;
2425

@@ -27,10 +28,10 @@ export class RemotesGitSubProvider extends RemotesGitProviderBase {
2728
this.container,
2829
repoPath,
2930
'origin',
30-
'https',
31+
protocol,
3132
domain,
3233
path,
33-
(await getRemoteProviderMatcher(this.container, providers))(url, domain, path),
34+
(await getRemoteProviderMatcher(this.container, providers))(url, domain, path, protocol),
3435
[
3536
{ type: 'fetch', url: url },
3637
{ type: 'push', url: url },

0 commit comments

Comments
 (0)