UNPKG

semantic-release-gh

Version:

The official GitHub plugin, modified to accept repositoryUrl as a parameter

51 lines 2.47 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.GetClient = void 0; const tslib_1 = require("tslib"); const rest_1 = require("@octokit/rest"); const bottleneck_1 = tslib_1.__importDefault(require("bottleneck")); const http_proxy_agent_1 = require("http-proxy-agent"); const https_proxy_agent_1 = require("https-proxy-agent"); const lodash_1 = require("lodash"); const p_retry_1 = tslib_1.__importDefault(require("p-retry")); const url_join_1 = tslib_1.__importDefault(require("url-join")); const rate_limit_1 = require("./definitions/rate-limit"); const HTTP_STATUS_400 = 400; const HTTP_STATUS_401 = 401; const HTTP_STATUS_403 = 403; const SKIP_RETRY_CODES = new Set([HTTP_STATUS_400, HTTP_STATUS_401, HTTP_STATUS_403]); const getThrottler = (0, lodash_1.memoize)((rate, globalThrottler) => new bottleneck_1.default({ minTime: (0, lodash_1.get)(rate_limit_1.RATE_LIMITS, rate) }).chain(globalThrottler)); const GetClient = ({ githubToken, githubUrl, githubApiPathPrefix, proxy }) => { const baseUrl = githubUrl && (0, url_join_1.default)(githubUrl, githubApiPathPrefix); const globalThrottler = new bottleneck_1.default({ minTime: rate_limit_1.GLOBAL_RATE_LIMIT }); const github = new rest_1.Octokit({ auth: `token ${githubToken}`, baseUrl, request: { agent: proxy ? baseUrl && new URL(baseUrl).protocol.replace(':', '') === 'http' ? new http_proxy_agent_1.HttpProxyAgent(proxy) : new https_proxy_agent_1.HttpsProxyAgent(proxy) : null } }); github.hook.wrap('request', (request, options) => { const access = options.method === 'GET' ? 'read' : 'write'; const rateCategory = options.url.startsWith('/search') ? 'search' : 'core'; const limitKey = [rateCategory, rate_limit_1.RATE_LIMITS[rateCategory][access] && access].filter(Boolean).join('.'); return (0, p_retry_1.default)(async () => { try { return await getThrottler(limitKey, globalThrottler).wrap(request)(options); } catch (error) { if (SKIP_RETRY_CODES.has(error.status)) { throw new p_retry_1.default.AbortError(error); } throw error; } }, rate_limit_1.RETRY_CONF); }); return github; }; exports.GetClient = GetClient; //# sourceMappingURL=get-client.js.map