diff --git a/dist/index.js b/dist/index.js index d1ad180..f6bc1c0 100644 --- a/dist/index.js +++ b/dist/index.js @@ -905,15 +905,17 @@ Object.defineProperty(exports, "__esModule", ({ value: true })); const ReportGenerator_1 = __importDefault(__nccwpck_require__(40637)); const core = __importStar(__nccwpck_require__(42186)); const rest_1 = __nccwpck_require__(55375); +const https_proxy_agent_1 = __nccwpck_require__(77219); function run() { return __awaiter(this, void 0, void 0, function* () { try { const token = getRequiredInputValue('token'); + const explicitProxy = core.getInput('https_proxy'); const generator = new ReportGenerator_1.default({ repository: getRequiredInputValue('repository'), ref: getRequiredInputValue('ref'), sarifId: core.getInput('sarif_report_id'), - octokit: new rest_1.Octokit({ auth: token }), + octokit: getOctokit(token, explicitProxy), outputDirectory: getRequiredInputValue('outputDir'), templating: { name: 'summary' @@ -931,6 +933,61 @@ run(); function getRequiredInputValue(key) { return core.getInput(key, { required: true }); } +function getOctokit(token, proxy) { + const baseUrl = getApiBaseUrl(); + const octokitOptions = { + baseUrl: baseUrl, + auth: token, + }; + const request = { + agent: getProxyAgent(baseUrl, proxy), + timeout: (10 * 1000) + }; + octokitOptions['request'] = request; + const client = new rest_1.Octokit(octokitOptions); + return client; +} +function getProxyAgent(baseUrl, proxy) { + if (proxy) { + // User has an explict proxy set, use it + core.info(`explicit proxy specified as '${proxy}'`); + return new https_proxy_agent_1.HttpsProxyAgent(proxy); + } + else { + // When loading from the environment, also respect no_proxy settings + const envProxy = process.env.http_proxy + || process.env.HTTP_PROXY + || process.env.https_proxy + || process.env.HTTPS_PROXY; + if (envProxy) { + core.info(`environment proxy specified as '${envProxy}'`); + const noProxy = process.env.no_proxy || process.env.NO_PROXY; + if (noProxy) { + core.info(`environment no_proxy set as '${noProxy}'`); + if (proxyExcluded(noProxy, baseUrl)) { + core.info(`environment proxy excluded from no_proxy settings`); + } + else { + core.info(`using proxy '${envProxy}' for GitHub API calls`); + return new https_proxy_agent_1.HttpsProxyAgent(envProxy); + } + } + } + } + return null; +} +function proxyExcluded(noProxy, baseUrl) { + if (noProxy) { + const noProxyHosts = noProxy.split(',').map(part => part.trim()); + const baseUrlHost = new URL(baseUrl).host; + core.debug(`noProxyHosts = ${JSON.stringify(noProxyHosts)}`); + core.debug(`baseUrlHost = ${baseUrlHost}`); + return noProxyHosts.indexOf(baseUrlHost) > -1; + } +} +function getApiBaseUrl(url) { + return url || process.env['GITHUB_API_URL'] || 'https://api.github.com'; +} /***/ }), @@ -7470,7 +7527,8 @@ function normalize (name) { } function statAll (fs, stat, cwd, ignore, entries, sort) { - const queue = (entries || ['.']).slice(0) + if (!entries) entries = ['.'] + const queue = entries.slice(0) return function loop (callback) { if (!queue.length) return callback(null) @@ -7480,7 +7538,7 @@ function statAll (fs, stat, cwd, ignore, entries, sort) { stat.call(fs, nextAbs, function (err, stat) { // ignore errors if the files were deleted while buffering - if (err) return callback(err.code === 'ENOENT' ? null : err) + if (err) return callback(entries.indexOf(next) === -1 && err.code === 'ENOENT' ? null : err) if (!stat.isDirectory()) return callback(null, next, stat) @@ -7988,7 +8046,7 @@ exports.decodePax = function decodePax (buf) { while (buf.length) { let i = 0 while (i < buf.length && buf[i] !== 32) i++ - const len = parseInt(buf.subarray(0, i).toString(), 10) + const len = parseInt(b4a.toString(buf.subarray(0, i)), 10) if (!len) return result const b = b4a.toString(buf.subarray(i + 1, len - 1)) @@ -8258,7 +8316,7 @@ function decodeOct (val, offset, length) { const end = clamp(indexOf(val, 32, offset, val.length), val.length, val.length) while (offset < end && val[offset] === 0) offset++ if (end === offset) return 0 - return parseInt(val.subarray(offset, end).toString(), 8) + return parseInt(b4a.toString(val.subarray(offset, end)), 8) } } @@ -8324,6 +8382,15 @@ class Sink extends Writable { if (this._pack._stream === this) this._continueOpen() } + _continuePack (err) { + if (this._callback === null) return + + const callback = this._callback + this._callback = null + + callback(err) + } + _continueOpen () { if (this._pack._stream === null) this._pack._stream = this @@ -8342,6 +8409,7 @@ class Sink extends Writable { if (this._isVoid) { this._finish() + this._continuePack(null) } cb(null) @@ -8354,7 +8422,10 @@ class Sink extends Writable { } if (this._isVoid) { - return cb(new Error('No body allowed for this entry')) + if (data.byteLength > 0) { + return cb(new Error('No body allowed for this entry')) + } + return cb() } this.written += data.byteLength @@ -8396,8 +8467,7 @@ class Sink extends Writable { _destroy (cb) { this._pack._done(this) - if (this._finished) this._callback(null) - else this._callback(this._getError()) + this._continuePack(this._finished ? null : this._getError()) cb() } @@ -8568,7039 +8638,6685 @@ function mapWritable (buf) { /***/ }), -/***/ 13980: -/***/ (function(module) { - -// MIT license (by Elan Shanker). -(function(globals) { - 'use strict'; - - var executeSync = function(){ - var args = Array.prototype.slice.call(arguments); - if (typeof args[0] === 'function'){ - args[0].apply(null, args.splice(1)); - } - }; +/***/ 40068: +/***/ ((__unused_webpack_module, exports) => { - var executeAsync = function(fn){ - if (typeof setImmediate === 'function') { - setImmediate(fn); - } else if (typeof process !== 'undefined' && process.nextTick) { - process.nextTick(fn); - } else { - setTimeout(fn, 0); - } - }; +"use strict"; - var makeIterator = function (tasks) { - var makeCallback = function (index) { - var fn = function () { - if (tasks.length) { - tasks[index].apply(null, arguments); - } - return fn.next(); - }; - fn.next = function () { - return (index < tasks.length - 1) ? makeCallback(index + 1): null; - }; - return fn; +Object.defineProperty(exports, "__esModule", ({ value: true })); +exports.awaitEachYieldedPromise = exports.maybeAsync = exports.maybeAsyncFn = void 0; +function* awaitYield(value) { + return (yield value); +} +function awaitYieldOf(generator) { + return awaitYield(awaitEachYieldedPromise(generator)); +} +const AwaitYield = awaitYield; +AwaitYield.of = awaitYieldOf; +/** + * Create a function that may or may not be async, using a generator + * + * Within the generator, call `yield* awaited(maybePromise)` to await a value + * that may or may not be a promise. + * + * If the inner function never yields a promise, it will return synchronously. + */ +function maybeAsyncFn(that, fn) { + return (...args) => { + const generator = fn.call(that, AwaitYield, ...args); + return awaitEachYieldedPromise(generator); }; - return makeCallback(0); - }; - - var _isArray = Array.isArray || function(maybeArray){ - return Object.prototype.toString.call(maybeArray) === '[object Array]'; - }; - - var waterfall = function (tasks, callback, forceAsync) { - var nextTick = forceAsync ? executeAsync : executeSync; - callback = callback || function () {}; - if (!_isArray(tasks)) { - var err = new Error('First argument to waterfall must be an array of functions'); - return callback(err); - } - if (!tasks.length) { - return callback(); +} +exports.maybeAsyncFn = maybeAsyncFn; +class Example { + constructor() { + this.maybeAsyncMethod = maybeAsyncFn(this, function* (awaited, a) { + yield* awaited(new Promise((resolve) => setTimeout(resolve, a))); + return 5; + }); } - var wrapIterator = function (iterator) { - return function (err) { - if (err) { - callback.apply(null, arguments); - callback = function () {}; - } else { - var args = Array.prototype.slice.call(arguments, 1); - var next = iterator.next(); - if (next) { - args.push(wrapIterator(next)); - } else { - args.push(callback); - } - nextTick(function () { - iterator.apply(null, args); - }); +} +function maybeAsync(that, startGenerator) { + const generator = startGenerator.call(that, AwaitYield); + return awaitEachYieldedPromise(generator); +} +exports.maybeAsync = maybeAsync; +function awaitEachYieldedPromise(gen) { + function handleNextStep(step) { + if (step.done) { + return step.value; } - }; - }; - wrapIterator(makeIterator(tasks))(); - }; - - if (typeof define !== 'undefined' && define.amd) { - define([], function () { - return waterfall; - }); // RequireJS - } else if ( true && module.exports) { - module.exports = waterfall; // CommonJS - } else { - globals.waterfall = waterfall; //