From 59fdb9dce20127460bf37f8078dc5323005364ac Mon Sep 17 00:00:00 2001 From: Alexander Kaserbacher Date: Sun, 9 May 2021 17:37:09 +0200 Subject: [PATCH 1/2] Use apiBaseUrl for Bitbucket server if it is set default to host otherwise Signed-off-by: Alexander Kaserbacher --- .../stages/publish/bitbucket.test.ts | 55 +++++++++++++++++++ .../scaffolder/stages/publish/bitbucket.ts | 11 ++-- 2 files changed, 62 insertions(+), 4 deletions(-) diff --git a/plugins/scaffolder-backend/src/scaffolder/stages/publish/bitbucket.test.ts b/plugins/scaffolder-backend/src/scaffolder/stages/publish/bitbucket.test.ts index 33fa51af1b..25ba11d7fb 100644 --- a/plugins/scaffolder-backend/src/scaffolder/stages/publish/bitbucket.test.ts +++ b/plugins/scaffolder-backend/src/scaffolder/stages/publish/bitbucket.test.ts @@ -170,4 +170,59 @@ describe('Bitbucket Publisher', () => { }); }); }); + + it('should use apiBaseUrl to create the repository if it is set', async () => { + server.use( + rest.post( + 'https://bitbucket.mycompany.com/bitbucket/rest/api/1.0/projects/project/repos', + (_, res, ctx) => + res( + ctx.status(201), + ctx.set('Content-Type', 'application/json'), + ctx.json({ + links: { + self: [ + { + href: + 'https://bitbucket.mycompany.com/bitbucket/projects/project/repos/repo', + }, + ], + clone: [ + { + name: 'http', + href: + 'https://bitbucket.mycompany.com/bitbucket/scm/project/repo', + }, + ], + }, + }), + ), + ), + ); + + const publisher = await BitbucketPublisher.fromConfig( + { + host: 'bitbucket.mycompany.com', + username: 'foo', + token: 'fake-token', + apiBaseUrl: 'https://bitbucket.mycompany.com/bitbucket/rest/api/1.0', + }, + { repoVisibility: 'private' }, + ); + + const result = await publisher.publish({ + values: { + storePath: 'https://bitbucket.mycompany.com/project/repo', + owner: 'bob', + }, + workspacePath, + logger: logger, + }); + + expect(result).toEqual({ + remoteUrl: 'https://bitbucket.mycompany.com/bitbucket/scm/project/repo', + catalogInfoUrl: + 'https://bitbucket.mycompany.com/bitbucket/projects/project/repos/repo/catalog-info.yaml', + }); + }); }); diff --git a/plugins/scaffolder-backend/src/scaffolder/stages/publish/bitbucket.ts b/plugins/scaffolder-backend/src/scaffolder/stages/publish/bitbucket.ts index aef0625c79..922662ebe3 100644 --- a/plugins/scaffolder-backend/src/scaffolder/stages/publish/bitbucket.ts +++ b/plugins/scaffolder-backend/src/scaffolder/stages/publish/bitbucket.ts @@ -42,6 +42,7 @@ export class BitbucketPublisher implements PublisherBase { token: config.token, appPassword: config.appPassword, username: config.username, + apiBaseUrl: config.apiBaseUrl, repoVisibility, }); } @@ -52,6 +53,7 @@ export class BitbucketPublisher implements PublisherBase { token?: string; appPassword?: string; username?: string; + apiBaseUrl?: string; repoVisibility: RepoVisibilityOptions; }, ) {} @@ -181,10 +183,11 @@ export class BitbucketPublisher implements PublisherBase { }; try { - response = await fetch( - `https://${this.config.host}/rest/api/1.0/projects/${project}/repos`, - options, - ); + const baseUrl = this.config.apiBaseUrl + ? this.config.apiBaseUrl + : `https://${this.config.host}/rest/api/1.0`; + + response = await fetch(`${baseUrl}/projects/${project}/repos`, options); } catch (e) { throw new Error(`Unable to create repository, ${e}`); } From 82ca1ac228db1cb40c79c84bab8ceb1ac4d8688e Mon Sep 17 00:00:00 2001 From: Alexander Kaserbacher Date: Sun, 9 May 2021 17:45:36 +0200 Subject: [PATCH 2/2] Add changeset Signed-off-by: Alexander Kaserbacher --- .changeset/forty-pumpkins-agree.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/forty-pumpkins-agree.md diff --git a/.changeset/forty-pumpkins-agree.md b/.changeset/forty-pumpkins-agree.md new file mode 100644 index 0000000000..2d8892c862 --- /dev/null +++ b/.changeset/forty-pumpkins-agree.md @@ -0,0 +1,5 @@ +--- +'@backstage/plugin-scaffolder-backend': patch +--- + +The apiBaseUrl setting for Bitbucket Server integrations will now be used when it is set. Otherwise, it will default back to the host setting.