UNPKG

@backstage/integration

Version:

Helpers for managing integrations towards external systems

60 lines (57 loc) 1.88 kB
import parseGitUrl from 'git-url-parse'; import { basicIntegrations, defaultScmResolveUrl } from '../helpers.esm.js'; import { readBitbucketIntegrationConfigs } from './config.esm.js'; class BitbucketIntegration { constructor(integrationConfig) { this.integrationConfig = integrationConfig; } static factory = ({ config }) => { const configs = readBitbucketIntegrationConfigs( config.getOptionalConfigArray("integrations.bitbucket") ?? [ // if integrations.bitbucket was not used assume the use was migrated to the new configs // and backport for the deprecated integration to be usable for other parts of the system // until these got migrated ...config.getOptionalConfigArray("integrations.bitbucketCloud") ?? [], ...config.getOptionalConfigArray("integrations.bitbucketServer") ?? [] ] ); return basicIntegrations( configs.map((c) => new BitbucketIntegration(c)), (i) => i.config.host ); }; get type() { return "bitbucket"; } get title() { return this.integrationConfig.host; } get config() { return this.integrationConfig; } resolveUrl(options) { const resolved = defaultScmResolveUrl(options); if (!options.lineNumber) { return resolved; } const url = new URL(resolved); if (this.integrationConfig.host === "bitbucket.org") { url.hash = `lines-${options.lineNumber}`; } else { url.hash = `${options.lineNumber}`; } return url.toString(); } resolveEditUrl(url) { const urlData = parseGitUrl(url); const editUrl = new URL(url); editUrl.searchParams.set("mode", "edit"); editUrl.searchParams.set("spa", "0"); editUrl.searchParams.set("at", urlData.ref); return editUrl.toString(); } } export { BitbucketIntegration }; //# sourceMappingURL=BitbucketIntegration.esm.js.map