UNPKG

@backstage/integration

Version:

Helpers for managing integrations towards external systems

52 lines (48 loc) 1.42 kB
'use strict'; var helpers = require('../helpers.cjs.js'); var config = require('./config.cjs.js'); class GithubIntegration { constructor(integrationConfig) { this.integrationConfig = integrationConfig; } static factory = ({ config: config$1 }) => { const configs = config.readGithubIntegrationConfigs( config$1.getOptionalConfigArray("integrations.github") ?? [] ); return helpers.basicIntegrations( configs.map((c) => new GithubIntegration(c)), (i) => i.config.host ); }; get type() { return "github"; } get title() { return this.integrationConfig.host; } get config() { return this.integrationConfig; } resolveUrl(options) { return replaceGithubUrlType(helpers.defaultScmResolveUrl(options), "tree"); } resolveEditUrl(url) { return replaceGithubUrlType(url, "edit"); } parseRateLimitInfo(response) { return { isRateLimited: response.status === 429 || response.status === 403 && response.headers.get("x-ratelimit-remaining") === "0" }; } } function replaceGithubUrlType(url, type) { return url.replace( /\/\/([^/]+)\/([^/]+)\/([^/]+)\/(blob|tree|edit)\//, (_, host, owner, repo) => { return `//${host}/${owner}/${repo}/${type}/`; } ); } exports.GithubIntegration = GithubIntegration; exports.replaceGithubUrlType = replaceGithubUrlType; //# sourceMappingURL=GithubIntegration.cjs.js.map