From 74802300c42808126b9b324a80445f7e6f13ba2d Mon Sep 17 00:00:00 2001 From: Matthew Bednarski Date: Sun, 15 Sep 2024 19:43:16 +0200 Subject: [PATCH 1/6] Update bitbucketServerPullRequest.ts - protocol from apiBaseUrl use the protocol from apiBaseUrl instead of hard-coded "https" Signed-off-by: Matthew Bednarski --- .../src/actions/bitbucketServerPullRequest.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) 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 440e402764..2ff06aa45d 100644 --- a/plugins/scaffolder-backend-module-bitbucket-server/src/actions/bitbucketServerPullRequest.ts +++ b/plugins/scaffolder-backend-module-bitbucket-server/src/actions/bitbucketServerPullRequest.ts @@ -237,6 +237,10 @@ const getDefaultBranch = async (opts: { } return defaultBranch; }; +const parseProtocol = (apiBaseUrl: string) => { + const url = new Url(apiBaseUrl); + return url.protocol || 'https'; +}; /** * Creates a BitbucketServer Pull Request action. * @public @@ -401,7 +405,8 @@ export function createPublishBitbucketServerPullRequestAction(options: { startPoint: latestCommit, }); - const remoteUrl = `https://${host}/scm/${project}/${repo}.git`; + const protocol = parseProtocol(apiBaseUrl); + const remoteUrl = `${protocol}://${host}/scm/${project}/${repo}.git`; const auth = authConfig.token ? { From 66a6b4579c79632b029cc68396d755c1275a9854 Mon Sep 17 00:00:00 2001 From: Matthew Bednarski Date: Mon, 16 Sep 2024 17:43:03 +0200 Subject: [PATCH 2/6] chore: adding generated changeset PR-26687 Signed-off-by: Matthew Bednarski --- .changeset/two-plums-fail.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/two-plums-fail.md diff --git a/.changeset/two-plums-fail.md b/.changeset/two-plums-fail.md new file mode 100644 index 0000000000..ed1b4af4ab --- /dev/null +++ b/.changeset/two-plums-fail.md @@ -0,0 +1,5 @@ +--- +'@backstage/plugin-scaffolder-backend-module-bitbucket-server': minor +--- + +Use protocol from Bitbucket Server apiBaseUrl config parameter instead of hard-coded https From f5436329884007ea1e04aef07817a200bdb1121f Mon Sep 17 00:00:00 2001 From: Matthew Bednarski Date: Mon, 16 Sep 2024 18:06:35 +0200 Subject: [PATCH 3/6] fix: wrong url instantiation Signed-off-by: Matthew Bednarski --- .../src/actions/bitbucketServerPullRequest.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 2ff06aa45d..ed7c0411b5 100644 --- a/plugins/scaffolder-backend-module-bitbucket-server/src/actions/bitbucketServerPullRequest.ts +++ b/plugins/scaffolder-backend-module-bitbucket-server/src/actions/bitbucketServerPullRequest.ts @@ -238,7 +238,7 @@ const getDefaultBranch = async (opts: { return defaultBranch; }; const parseProtocol = (apiBaseUrl: string) => { - const url = new Url(apiBaseUrl); + const url = new URL(apiBaseUrl); return url.protocol || 'https'; }; /** From b1e5501b900844dc64f083c63e5813f5c1bb83af Mon Sep 17 00:00:00 2001 From: Matthew Bednarski Date: Mon, 23 Sep 2024 12:30:13 +0200 Subject: [PATCH 4/6] 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 ? { From 2f1a0e944c4782632ab771d815173f188f6f6d5e Mon Sep 17 00:00:00 2001 From: blam Date: Tue, 24 Sep 2024 10:58:43 +0200 Subject: [PATCH 5/6] chore: fix prettier\ Signed-off-by: blam --- .../src/actions/bitbucketServerPullRequest.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 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 51d097410b..fe79935a1d 100644 --- a/plugins/scaffolder-backend-module-bitbucket-server/src/actions/bitbucketServerPullRequest.ts +++ b/plugins/scaffolder-backend-module-bitbucket-server/src/actions/bitbucketServerPullRequest.ts @@ -237,7 +237,7 @@ const getDefaultBranch = async (opts: { } return defaultBranch; }; -const isApiBaseUrlHttps = (apiBaseUrl: string) : boolean => { +const isApiBaseUrlHttps = (apiBaseUrl: string): boolean => { const url = new URL(apiBaseUrl); return url.protocol === 'https:'; }; @@ -406,7 +406,9 @@ export function createPublishBitbucketServerPullRequestAction(options: { }); const isHttps: boolean = isApiBaseUrlHttps(apiBaseUrl); - const remoteUrl = `${isHttps ? 'https' : 'http' }://${host}/scm/${project}/${repo}.git`; + const remoteUrl = `${ + isHttps ? 'https' : 'http' + }://${host}/scm/${project}/${repo}.git`; const auth = authConfig.token ? { From 1aecd6a0ca32021e5b29e0aab0957e1b7c970b1d Mon Sep 17 00:00:00 2001 From: blam Date: Tue, 24 Sep 2024 10:59:28 +0200 Subject: [PATCH 6/6] chore: Fixing changeset Signed-off-by: blam --- .changeset/two-plums-fail.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.changeset/two-plums-fail.md b/.changeset/two-plums-fail.md index ed1b4af4ab..9d976ab4b5 100644 --- a/.changeset/two-plums-fail.md +++ b/.changeset/two-plums-fail.md @@ -1,5 +1,5 @@ --- -'@backstage/plugin-scaffolder-backend-module-bitbucket-server': minor +'@backstage/plugin-scaffolder-backend-module-bitbucket-server': patch --- Use protocol from Bitbucket Server apiBaseUrl config parameter instead of hard-coded https