@backstage/integration
Version:
Helpers for managing integrations towards external systems
49 lines (46 loc) • 1.38 kB
JavaScript
import { basicIntegrations, defaultScmResolveUrl } from '../helpers.esm.js';
import { readGithubIntegrationConfigs } from './config.esm.js';
class GithubIntegration {
constructor(integrationConfig) {
this.integrationConfig = integrationConfig;
}
static factory = ({ config }) => {
const configs = readGithubIntegrationConfigs(
config.getOptionalConfigArray("integrations.github") ?? []
);
return 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(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}/`;
}
);
}
export { GithubIntegration, replaceGithubUrlType };
//# sourceMappingURL=GithubIntegration.esm.js.map