diff --git a/.changeset/wise-foxes-confess.md b/.changeset/wise-foxes-confess.md new file mode 100644 index 0000000000..8322b66555 --- /dev/null +++ b/.changeset/wise-foxes-confess.md @@ -0,0 +1,5 @@ +--- +'@backstage/plugin-scaffolder-backend': patch +--- + +Fix the support for custom defaultBranch values for Bitbucket Cloud at the `publish:bitbucket` scaffolder action. diff --git a/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/bitbucket.test.ts b/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/bitbucket.test.ts index 5493219d57..96fd8184ca 100644 --- a/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/bitbucket.test.ts +++ b/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/bitbucket.test.ts @@ -567,4 +567,47 @@ describe('publish:bitbucket', () => { 'https://bitbucket.org/workspace/repo/src/master', ); }); + + it('should call outputs with the correct urls with correct default branch', async () => { + server.use( + rest.post( + 'https://api.bitbucket.org/2.0/repositories/workspace/repo', + (_, res, ctx) => + res( + ctx.status(200), + ctx.set('Content-Type', 'application/json'), + ctx.json({ + links: { + html: { + href: 'https://bitbucket.org/workspace/repo', + }, + clone: [ + { + name: 'https', + href: 'https://bitbucket.org/workspace/cloneurl', + }, + ], + }, + }), + ), + ), + ); + + await action.handler({ + ...mockContext, + input: { + ...mockContext.input, + defaultBranch: 'main', + }, + }); + + expect(mockContext.output).toHaveBeenCalledWith( + 'remoteUrl', + 'https://bitbucket.org/workspace/cloneurl', + ); + expect(mockContext.output).toHaveBeenCalledWith( + 'repoContentsUrl', + 'https://bitbucket.org/workspace/repo/src/main', + ); + }); }); diff --git a/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/bitbucket.ts b/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/bitbucket.ts index 47ebce0550..07e67978cd 100644 --- a/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/bitbucket.ts +++ b/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/bitbucket.ts @@ -31,6 +31,7 @@ const createBitbucketCloudRepository = async (opts: { repo: string; description?: string; repoVisibility: 'private' | 'public'; + mainBranch: string; authorization: string; }) => { const { @@ -39,6 +40,7 @@ const createBitbucketCloudRepository = async (opts: { repo, description, repoVisibility, + mainBranch, authorization, } = opts; @@ -82,8 +84,9 @@ const createBitbucketCloudRepository = async (opts: { } } - // TODO use the urlReader to get the default branch - const repoContentsUrl = `${r.links.html.href}/src/master`; + // "mainbranch.name" cannot be set neither at create nor update of the repo + // the first pushed branch will be set as "main branch" then + const repoContentsUrl = `${r.links.html.href}/src/${mainBranch}`; return { remoteUrl, repoContentsUrl }; }; @@ -324,6 +327,7 @@ export function createPublishBitbucketAction(options: { project, repo, repoVisibility, + mainBranch: defaultBranch, description, apiBaseUrl, });