From b1e5501b900844dc64f083c63e5813f5c1bb83af Mon Sep 17 00:00:00 2001 From: Matthew Bednarski Date: Mon, 23 Sep 2024 12:30:13 +0200 Subject: [PATCH] Update bitbucketServerPullRequest.ts - refactor parseProtocol to isApiBaseUrlHttps refactor parseProtocol to isApiBaseUrlHttps; ie. instead of taking the protocol scheme from the URL object, use boolean based on the apiBaseUrl to get whether to use "http" or "https". The default will still be "https". Signed-off-by: Matthew Bednarski --- .../src/actions/bitbucketServerPullRequest.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/plugins/scaffolder-backend-module-bitbucket-server/src/actions/bitbucketServerPullRequest.ts b/plugins/scaffolder-backend-module-bitbucket-server/src/actions/bitbucketServerPullRequest.ts index ed7c0411b5..51d097410b 100644 --- a/plugins/scaffolder-backend-module-bitbucket-server/src/actions/bitbucketServerPullRequest.ts +++ b/plugins/scaffolder-backend-module-bitbucket-server/src/actions/bitbucketServerPullRequest.ts @@ -237,9 +237,9 @@ const getDefaultBranch = async (opts: { } return defaultBranch; }; -const parseProtocol = (apiBaseUrl: string) => { +const isApiBaseUrlHttps = (apiBaseUrl: string) : boolean => { const url = new URL(apiBaseUrl); - return url.protocol || 'https'; + return url.protocol === 'https:'; }; /** * Creates a BitbucketServer Pull Request action. @@ -405,8 +405,8 @@ export function createPublishBitbucketServerPullRequestAction(options: { startPoint: latestCommit, }); - const protocol = parseProtocol(apiBaseUrl); - const remoteUrl = `${protocol}://${host}/scm/${project}/${repo}.git`; + const isHttps: boolean = isApiBaseUrlHttps(apiBaseUrl); + const remoteUrl = `${isHttps ? 'https' : 'http' }://${host}/scm/${project}/${repo}.git`; const auth = authConfig.token ? {