UNPKG

@backstage/integration

Version:

Helpers for managing integrations towards external systems

66 lines (60 loc) 2.1 kB
'use strict'; var parseGitUrl = require('git-url-parse'); var helpers = require('../helpers.cjs.js'); var config = require('./config.cjs.js'); function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e : { default: e }; } var parseGitUrl__default = /*#__PURE__*/_interopDefaultCompat(parseGitUrl); class BitbucketIntegration { constructor(integrationConfig) { this.integrationConfig = integrationConfig; } static factory = ({ config: config$1 }) => { const configs = config.readBitbucketIntegrationConfigs( config$1.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$1.getOptionalConfigArray("integrations.bitbucketCloud") ?? [], ...config$1.getOptionalConfigArray("integrations.bitbucketServer") ?? [] ] ); return helpers.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 = helpers.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__default.default(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(); } } exports.BitbucketIntegration = BitbucketIntegration; //# sourceMappingURL=BitbucketIntegration.cjs.js.map