feat(bitbucket): ensure apiBaseUrl, replace hardcoded cases

Ensure presence of apiBaseUrl for bitbucket
integrations for both cases Bitbucket Cloud and
Bitbucket Server by setting the default for
Bitbucket Server at the integration config, too.

Replace hardcoded uses of the default apiBaseUrl
with the use of the integration config's value.

Signed-off-by: Patrick Jungermann <Patrick.Jungermann@gmail.com>
This commit is contained in:
Patrick Jungermann
2022-02-24 12:45:04 +01:00
parent dd2e1eb59a
commit 34af86517c
7 changed files with 33 additions and 39 deletions
+1 -1
View File
@@ -88,7 +88,7 @@ export class BitbucketIntegration implements ScmIntegration {
// @public
export type BitbucketIntegrationConfig = {
host: string;
apiBaseUrl?: string;
apiBaseUrl: string;
token?: string;
username?: string;
appPassword?: string;
+5 -5
View File
@@ -36,12 +36,10 @@ export type BitbucketIntegrationConfig = {
* The base URL of the API of this provider, e.g. "https://api.bitbucket.org/2.0",
* with no trailing slash.
*
* May be omitted specifically for Bitbucket Cloud; then it will be deduced.
*
* The API will always be preferred if both its base URL and a token are
* present.
* Values omitted at the optional property at the app-config will be deduced
* from the "host" value.
*/
apiBaseUrl?: string;
apiBaseUrl: string;
/**
* The authorization token to use for requests to a Bitbucket Server provider.
@@ -90,6 +88,8 @@ export function readBitbucketIntegrationConfig(
apiBaseUrl = trimEnd(apiBaseUrl, '/');
} else if (host === BITBUCKET_HOST) {
apiBaseUrl = BITBUCKET_API_BASE_URL;
} else {
apiBaseUrl = `https://${host}/rest/api/1.0`;
}
return {
+8 -2
View File
@@ -24,7 +24,10 @@ import {
describe('basicIntegrations', () => {
describe('byUrl', () => {
it('handles hosts without a port', () => {
const integration = new BitbucketIntegration({ host: 'host.com' });
const integration = new BitbucketIntegration({
host: 'host.com',
apiBaseUrl: 'a',
});
const integrations = basicIntegrations<BitbucketIntegration>(
[integration],
i => i.config.host,
@@ -33,7 +36,10 @@ describe('basicIntegrations', () => {
expect(integrations.byUrl('https://host.com:8080/a')).toBeUndefined();
});
it('handles hosts with a port', () => {
const integration = new BitbucketIntegration({ host: 'host.com:8080' });
const integration = new BitbucketIntegration({
host: 'host.com:8080',
apiBaseUrl: 'a',
});
const integrations = basicIntegrations<BitbucketIntegration>(
[integration],
i => i.config.host,