Fixed setting default branch for bitbucket server.

The main problem comes from `outputs.repoContentsUrl` that does not have reference to a branch, so that subsequent `catalog:register` action fails.

Bitbucket Cloud does not support setting default branch from REST API, but since the first pushed branch becomes default branch it works with current approach.

Signed-off-by: Arthur Gavlyukovskiy <agavlyukovskiy@gmail.com>
This commit is contained in:
Arthur Gavlyukovskiy
2022-10-05 23:20:17 +02:00
parent 32aa6532bf
commit 4880d43e25
3 changed files with 59 additions and 10 deletions
+5
View File
@@ -0,0 +1,5 @@
---
'@backstage/plugin-scaffolder-backend': patch
---
Fixed setting default branch for Bitbucket Server
@@ -123,7 +123,11 @@ describe('publish:bitbucketServer', () => {
'https://hosted.bitbucket.com/rest/api/1.0/projects/project/repos',
(req, res, ctx) => {
expect(req.headers.get('Authorization')).toBe('Bearer thing');
expect(req.body).toEqual({ public: false, name: 'repo' });
expect(req.body).toEqual({
public: false,
name: 'repo',
defaultBranch: 'master',
});
return res(
ctx.status(201),
ctx.set('Content-Type', 'application/json'),
@@ -165,7 +169,11 @@ describe('publish:bitbucketServer', () => {
expect(req.headers.get('Authorization')).toBe(
'Basic dGVzdC11c2VyOnRlc3QtcGFzc3dvcmQ=',
);
expect(req.body).toEqual({ public: false, name: 'repo' });
expect(req.body).toEqual({
public: false,
name: 'repo',
defaultBranch: 'master',
});
return res(
ctx.status(201),
ctx.set('Content-Type', 'application/json'),
@@ -206,7 +214,11 @@ describe('publish:bitbucketServer', () => {
'https://no-credentials.bitbucket.com/rest/api/1.0/projects/project/repos',
(req, res, ctx) => {
expect(req.headers.get('Authorization')).toBe(`Bearer ${token}`);
expect(req.body).toEqual({ public: false, name: 'repo' });
expect(req.body).toEqual({
public: false,
name: 'repo',
defaultBranch: 'master',
});
return res(
ctx.status(201),
ctx.set('Content-Type', 'application/json'),
@@ -327,7 +339,11 @@ describe('publish:bitbucketServer', () => {
'https://hosted.bitbucket.com/rest/api/1.0/projects/project/repos',
(req, res, ctx) => {
expect(req.headers.get('Authorization')).toBe('Bearer thing');
expect(req.body).toEqual({ public: false, name: 'repo' });
expect(req.body).toEqual({
public: false,
name: 'repo',
defaultBranch: 'master',
});
return res(
ctx.status(201),
ctx.set('Content-Type', 'application/json'),
@@ -371,7 +387,11 @@ describe('publish:bitbucketServer', () => {
expect(req.headers.get('Authorization')).toBe(
'Basic dGVzdC11c2VyOnRlc3QtcGFzc3dvcmQ=',
);
expect(req.body).toEqual({ public: false, name: 'repo' });
expect(req.body).toEqual({
public: false,
name: 'repo',
defaultBranch: 'master',
});
return res(
ctx.status(201),
ctx.set('Content-Type', 'application/json'),
@@ -419,7 +439,11 @@ describe('publish:bitbucketServer', () => {
'https://hosted.bitbucket.com/rest/api/1.0/projects/project/repos',
(req, res, ctx) => {
expect(req.headers.get('Authorization')).toBe('Bearer thing');
expect(req.body).toEqual({ public: false, name: 'repo' });
expect(req.body).toEqual({
public: false,
name: 'repo',
defaultBranch: 'main',
});
return res(
ctx.status(201),
ctx.set('Content-Type', 'application/json'),
@@ -495,7 +519,11 @@ describe('publish:bitbucketServer', () => {
'https://hosted.bitbucket.com/rest/api/1.0/projects/project/repos',
(req, res, ctx) => {
expect(req.headers.get('Authorization')).toBe('Bearer thing');
expect(req.body).toEqual({ public: false, name: 'repo' });
expect(req.body).toEqual({
public: false,
name: 'repo',
defaultBranch: 'master',
});
return res(
ctx.status(201),
ctx.set('Content-Type', 'application/json'),
@@ -562,7 +590,11 @@ describe('publish:bitbucketServer', () => {
'https://hosted.bitbucket.com/rest/api/1.0/projects/project/repos',
(req, res, ctx) => {
expect(req.headers.get('Authorization')).toBe('Bearer thing');
expect(req.body).toEqual({ public: false, name: 'repo' });
expect(req.body).toEqual({
public: false,
name: 'repo',
defaultBranch: 'master',
});
return res(
ctx.status(201),
ctx.set('Content-Type', 'application/json'),
@@ -605,7 +637,11 @@ describe('publish:bitbucketServer', () => {
'https://hosted.bitbucket.com/rest/api/1.0/projects/project/repos',
(req, res, ctx) => {
expect(req.headers.get('Authorization')).toBe('Bearer thing');
expect(req.body).toEqual({ public: false, name: 'repo' });
expect(req.body).toEqual({
public: false,
name: 'repo',
defaultBranch: 'master',
});
return res(
ctx.status(201),
ctx.set('Content-Type', 'application/json'),
@@ -647,7 +683,11 @@ describe('publish:bitbucketServer', () => {
'https://hosted.bitbucket.com/rest/api/1.0/projects/project/repos',
(req, res, ctx) => {
expect(req.headers.get('Authorization')).toBe('Bearer thing');
expect(req.body).toEqual({ public: false, name: 'repo' });
expect(req.body).toEqual({
public: false,
name: 'repo',
defaultBranch: 'main',
});
return res(
ctx.status(201),
ctx.set('Content-Type', 'application/json'),
@@ -30,6 +30,7 @@ const createRepository = async (opts: {
repo: string;
description?: string;
repoVisibility: 'private' | 'public';
defaultBranch: string;
authorization: string;
apiBaseUrl: string;
}) => {
@@ -39,6 +40,7 @@ const createRepository = async (opts: {
description,
authorization,
repoVisibility,
defaultBranch,
apiBaseUrl,
} = opts;
@@ -48,6 +50,7 @@ const createRepository = async (opts: {
body: JSON.stringify({
name: repo,
description: description,
defaultBranch: defaultBranch,
public: repoVisibility === 'public',
}),
headers: {
@@ -232,6 +235,7 @@ export function createPublishBitbucketServerAction(options: {
project,
repo,
repoVisibility,
defaultBranch,
description,
apiBaseUrl,
});