From 8c04d7acd06b1ea59c8aa636773995ddf692635f Mon Sep 17 00:00:00 2001 From: Kamil Andrzejewski Date: Mon, 13 Jan 2025 14:23:19 +0100 Subject: [PATCH] chore: update getFile in BitbucketServerClient to use REST API paths for URL construction Signed-off-by: Kamil Andrzejewski --- .changeset/thick-radios-wink.md | 5 +++++ .../src/lib/BitbucketServerClient.test.ts | 2 +- .../src/lib/BitbucketServerClient.ts | 3 +-- 3 files changed, 7 insertions(+), 3 deletions(-) create mode 100644 .changeset/thick-radios-wink.md diff --git a/.changeset/thick-radios-wink.md b/.changeset/thick-radios-wink.md new file mode 100644 index 0000000000..25b12cc09f --- /dev/null +++ b/.changeset/thick-radios-wink.md @@ -0,0 +1,5 @@ +--- +'@backstage/plugin-catalog-backend-module-bitbucket-server': patch +--- + +Updated the `getFile` method in `BitbucketServerClient` to use `this.config.apiBaseUrl` directly for constructing the API request URL, removing the creation of an unnecessary `URL` object. The method now relies on REST API paths for accessing resources instead of direct access, ensuring better alignment with Bitbucket's API conventions. diff --git a/plugins/catalog-backend-module-bitbucket-server/src/lib/BitbucketServerClient.test.ts b/plugins/catalog-backend-module-bitbucket-server/src/lib/BitbucketServerClient.test.ts index db2a05d0b1..6abcede9de 100644 --- a/plugins/catalog-backend-module-bitbucket-server/src/lib/BitbucketServerClient.test.ts +++ b/plugins/catalog-backend-module-bitbucket-server/src/lib/BitbucketServerClient.test.ts @@ -153,7 +153,7 @@ describe('BitbucketServerClient', () => { it('getFile', async () => { server.use( rest.get( - `https://${config.host}/projects/test-project/repos/test-repo/raw/catalog-info.yaml`, + `${config.apiBaseUrl}/projects/test-project/repos/test-repo/raw/catalog-info.yaml`, (req, res, ctx) => { if ( req.headers.get('authorization') !== diff --git a/plugins/catalog-backend-module-bitbucket-server/src/lib/BitbucketServerClient.ts b/plugins/catalog-backend-module-bitbucket-server/src/lib/BitbucketServerClient.ts index 73373ffff1..3dd61d64e7 100644 --- a/plugins/catalog-backend-module-bitbucket-server/src/lib/BitbucketServerClient.ts +++ b/plugins/catalog-backend-module-bitbucket-server/src/lib/BitbucketServerClient.ts @@ -77,9 +77,8 @@ export class BitbucketServerClient { repo: string; path: string; }): Promise { - const base = new URL(this.config.apiBaseUrl); return throttledFetch( - `${base.protocol}//${base.host}/projects/${options.projectKey}/repos/${options.repo}/raw/${options.path}`, + `${this.config.apiBaseUrl}/projects/${options.projectKey}/repos/${options.repo}/raw/${options.path}`, getBitbucketServerRequestOptions(this.config), ); }