Merge pull request #5624 from alexksbr/bitbucket-api-base-url
Bitbucket Server apiBaseUrl
This commit is contained in:
@@ -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.
|
||||
@@ -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',
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -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}`);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user