@backstage/integration
Version:
Helpers for managing integrations towards external systems
62 lines (58 loc) • 1.52 kB
JavaScript
;
var helpers = require('../helpers.cjs.js');
var config = require('./config.cjs.js');
var core = require('./core.cjs.js');
class GerritIntegration {
constructor(integrationConfig) {
this.integrationConfig = integrationConfig;
}
static factory = ({ config: config$1 }) => {
const configs = config.readGerritIntegrationConfigs(
config$1.getOptionalConfigArray("integrations.gerrit") ?? []
);
return helpers.basicIntegrations(
configs.map((c) => new GerritIntegration(c)),
(i) => i.config.host
);
};
get type() {
return "gerrit";
}
get title() {
return this.integrationConfig.host;
}
get config() {
return this.integrationConfig;
}
resolveUrl(options) {
const { url, base, lineNumber } = options;
let updated;
if (url.startsWith("/")) {
const { basePath } = core.parseGitilesUrlRef(this.config, base);
return basePath + url;
}
if (url) {
updated = new URL(url, base);
} else {
updated = new URL(base);
}
if (lineNumber) {
updated.hash = lineNumber.toString();
}
return updated.toString();
}
resolveEditUrl(url) {
if (this.config.disableEditUrl) {
return url;
}
const parsed = core.parseGitilesUrlRef(this.config, url);
return core.buildGerritEditUrl(
this.config,
parsed.project,
parsed.ref,
parsed.path
);
}
}
exports.GerritIntegration = GerritIntegration;
//# sourceMappingURL=GerritIntegration.cjs.js.map