UNPKG

@backstage/integration

Version:

Helpers for managing integrations towards external systems

46 lines (43 loc) 1.45 kB
import { trimEnd } from 'lodash'; import { isValidHost } from '../helpers.esm.js'; const BITBUCKET_HOST = "bitbucket.org"; const BITBUCKET_API_BASE_URL = "https://api.bitbucket.org/2.0"; function readBitbucketIntegrationConfig(config) { const host = config.getOptionalString("host") ?? BITBUCKET_HOST; let apiBaseUrl = config.getOptionalString("apiBaseUrl"); const token = config.getOptionalString("token")?.trim(); const username = config.getOptionalString("username"); const appPassword = config.getOptionalString("appPassword")?.trim(); if (!isValidHost(host)) { throw new Error( `Invalid Bitbucket integration config, '${host}' is not a valid host` ); } if (apiBaseUrl) { apiBaseUrl = trimEnd(apiBaseUrl, "/"); } else if (host === BITBUCKET_HOST) { apiBaseUrl = BITBUCKET_API_BASE_URL; } else { apiBaseUrl = `https://${host}/rest/api/1.0`; } return { host, apiBaseUrl, token, username, appPassword, commitSigningKey: config.getOptionalString("commitSigningKey") }; } function readBitbucketIntegrationConfigs(configs) { const result = configs.map(readBitbucketIntegrationConfig); if (!result.some((c) => c.host === BITBUCKET_HOST)) { result.push({ host: BITBUCKET_HOST, apiBaseUrl: BITBUCKET_API_BASE_URL }); } return result; } export { readBitbucketIntegrationConfig, readBitbucketIntegrationConfigs }; //# sourceMappingURL=config.esm.js.map