Merge pull request #9794 from Bonial-International-GmbH/PJ_bitbucket_custom-defaultBranch

fix(scaffolder,bitbucket): support custom defaultBranch for Bitbucket Cloud
This commit is contained in:
Fredrik Adelöw
2022-02-25 11:44:23 +01:00
committed by GitHub
3 changed files with 54 additions and 2 deletions
+5
View File
@@ -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.
@@ -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',
);
});
});
@@ -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,
});