Use apiBaseUrl for Bitbucket server if it is set
default to host otherwise Signed-off-by: Alexander Kaserbacher <alex.kaserbacher@icloud.com>
This commit is contained in:
@@ -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