diff --git a/dist/index.js b/dist/index.js index ca36e33..4264172 100644 --- a/dist/index.js +++ b/dist/index.js @@ -1160,12 +1160,17 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; Object.defineProperty(exports, "__esModule", ({ value: true })); exports.GitHubHelper = void 0; const core = __importStar(__nccwpck_require__(2186)); const octokit_client_1 = __nccwpck_require__(5040); +const p_limit_1 = __importDefault(__nccwpck_require__(3783)); const utils = __importStar(__nccwpck_require__(918)); const ERROR_PR_REVIEW_TOKEN_SCOPE = 'Validation Failed: "Could not resolve to a node with the global id of'; +const blobCreationLimit = (0, p_limit_1.default)(8); class GitHubHelper { constructor(githubServerHostname, token) { const options = {}; @@ -1295,7 +1300,7 @@ class GitHubHelper { let sha = null; if (status === 'A' || status === 'M') { core.info(`Creating blob for file '${path}'`); - const { data: blob } = yield this.octokit.rest.git.createBlob(Object.assign(Object.assign({}, repository), { content: utils.readFileBase64([repoPath, path]), encoding: 'base64' })); + const { data: blob } = yield blobCreationLimit(() => this.octokit.rest.git.createBlob(Object.assign(Object.assign({}, repository), { content: utils.readFileBase64([repoPath, path]), encoding: 'base64' }))); sha = blob.sha; } return { @@ -63343,6 +63348,200 @@ function parseParams (str) { module.exports = parseParams +/***/ }), + +/***/ 3783: +/***/ ((__unused_webpack___webpack_module__, __webpack_exports__, __nccwpck_require__) => { + +"use strict"; +// ESM COMPAT FLAG +__nccwpck_require__.r(__webpack_exports__); + +// EXPORTS +__nccwpck_require__.d(__webpack_exports__, { + "default": () => (/* binding */ pLimit) +}); + +;// CONCATENATED MODULE: ./node_modules/yocto-queue/index.js +/* +How it works: +`this.#head` is an instance of `Node` which keeps track of its current value and nests another instance of `Node` that keeps the value that comes after it. When a value is provided to `.enqueue()`, the code needs to iterate through `this.#head`, going deeper and deeper to find the last value. However, iterating through every single item is slow. This problem is solved by saving a reference to the last value as `this.#tail` so that it can reference it to add a new value. +*/ + +class Node { + value; + next; + + constructor(value) { + this.value = value; + } +} + +class Queue { + #head; + #tail; + #size; + + constructor() { + this.clear(); + } + + enqueue(value) { + const node = new Node(value); + + if (this.#head) { + this.#tail.next = node; + this.#tail = node; + } else { + this.#head = node; + this.#tail = node; + } + + this.#size++; + } + + dequeue() { + const current = this.#head; + if (!current) { + return; + } + + this.#head = this.#head.next; + this.#size--; + return current.value; + } + + peek() { + if (!this.#head) { + return; + } + + return this.#head.value; + + // TODO: Node.js 18. + // return this.#head?.value; + } + + clear() { + this.#head = undefined; + this.#tail = undefined; + this.#size = 0; + } + + get size() { + return this.#size; + } + + * [Symbol.iterator]() { + let current = this.#head; + + while (current) { + yield current.value; + current = current.next; + } + } +} + +;// CONCATENATED MODULE: ./node_modules/p-limit/index.js + + +function pLimit(concurrency) { + validateConcurrency(concurrency); + + const queue = new Queue(); + let activeCount = 0; + + const resumeNext = () => { + if (activeCount < concurrency && queue.size > 0) { + queue.dequeue()(); + // Since `pendingCount` has been decreased by one, increase `activeCount` by one. + activeCount++; + } + }; + + const next = () => { + activeCount--; + + resumeNext(); + }; + + const run = async (function_, resolve, arguments_) => { + const result = (async () => function_(...arguments_))(); + + resolve(result); + + try { + await result; + } catch {} + + next(); + }; + + const enqueue = (function_, resolve, arguments_) => { + // Queue `internalResolve` instead of the `run` function + // to preserve asynchronous context. + new Promise(internalResolve => { + queue.enqueue(internalResolve); + }).then( + run.bind(undefined, function_, resolve, arguments_), + ); + + (async () => { + // This function needs to wait until the next microtask before comparing + // `activeCount` to `concurrency`, because `activeCount` is updated asynchronously + // after the `internalResolve` function is dequeued and called. The comparison in the if-statement + // needs to happen asynchronously as well to get an up-to-date value for `activeCount`. + await Promise.resolve(); + + if (activeCount < concurrency) { + resumeNext(); + } + })(); + }; + + const generator = (function_, ...arguments_) => new Promise(resolve => { + enqueue(function_, resolve, arguments_); + }); + + Object.defineProperties(generator, { + activeCount: { + get: () => activeCount, + }, + pendingCount: { + get: () => queue.size, + }, + clearQueue: { + value() { + queue.clear(); + }, + }, + concurrency: { + get: () => concurrency, + + set(newConcurrency) { + validateConcurrency(newConcurrency); + concurrency = newConcurrency; + + queueMicrotask(() => { + // eslint-disable-next-line no-unmodified-loop-condition + while (activeCount < concurrency && queue.size > 0) { + resumeNext(); + } + }); + }, + }, + }); + + return generator; +} + +function validateConcurrency(concurrency) { + if (!((Number.isInteger(concurrency) || concurrency === Number.POSITIVE_INFINITY) && concurrency > 0)) { + throw new TypeError('Expected `concurrency` to be a number from 1 and up'); + } +} + + /***/ }), /***/ 1907: @@ -63386,6 +63585,34 @@ module.exports = JSON.parse('[[[0,44],"disallowed_STD3_valid"],[[45,46],"valid"] /******/ } /******/ /************************************************************************/ +/******/ /* webpack/runtime/define property getters */ +/******/ (() => { +/******/ // define getter functions for harmony exports +/******/ __nccwpck_require__.d = (exports, definition) => { +/******/ for(var key in definition) { +/******/ if(__nccwpck_require__.o(definition, key) && !__nccwpck_require__.o(exports, key)) { +/******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] }); +/******/ } +/******/ } +/******/ }; +/******/ })(); +/******/ +/******/ /* webpack/runtime/hasOwnProperty shorthand */ +/******/ (() => { +/******/ __nccwpck_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop)) +/******/ })(); +/******/ +/******/ /* webpack/runtime/make namespace object */ +/******/ (() => { +/******/ // define __esModule on exports +/******/ __nccwpck_require__.r = (exports) => { +/******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { +/******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); +/******/ } +/******/ Object.defineProperty(exports, '__esModule', { value: true }); +/******/ }; +/******/ })(); +/******/ /******/ /* webpack/runtime/compat */ /******/ /******/ if (typeof __nccwpck_require__ !== 'undefined') __nccwpck_require__.ab = __dirname + "/"; diff --git a/package-lock.json b/package-lock.json index a119dbb..67c8814 100644 --- a/package-lock.json +++ b/package-lock.json @@ -14,6 +14,7 @@ "@octokit/core": "^4.2.4", "@octokit/plugin-paginate-rest": "^5.0.1", "@octokit/plugin-rest-endpoint-methods": "^6.8.1", + "p-limit": "^6.1.0", "proxy-from-env": "^1.1.0", "undici": "^6.19.8", "uuid": "^9.0.1" @@ -5311,6 +5312,33 @@ "node": "^14.15.0 || ^16.10.0 || >=18.0.0" } }, + "node_modules/jest-changed-files/node_modules/p-limit": { + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/p-limit/-/p-limit-3.1.0.tgz", + "integrity": "sha512-TYOanM3wGwNGsZN2cVTYPArw454xnXj5qmWF1bEoAc4+cU/ol7GVh7odevjp1FNHduHc3KZMcFduxU5Xc6uJRQ==", + "dev": true, + "dependencies": { + "yocto-queue": "^0.1.0" + }, + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/jest-changed-files/node_modules/yocto-queue": { + "version": "0.1.0", + "resolved": "https://registry.npmjs.org/yocto-queue/-/yocto-queue-0.1.0.tgz", + "integrity": "sha512-rVksvsnNCdJ/ohGc6xgPwyN8eheCxsiLM8mxuE/t/mOVqJewPuO1miLpTHQiRgTKCLexL4MeAFVagts7HmNZ2Q==", + "dev": true, + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, "node_modules/jest-circus": { "version": "29.7.0", "resolved": "https://registry.npmjs.org/jest-circus/-/jest-circus-29.7.0.tgz", @@ -5342,6 +5370,33 @@ "node": "^14.15.0 || ^16.10.0 || >=18.0.0" } }, + "node_modules/jest-circus/node_modules/p-limit": { + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/p-limit/-/p-limit-3.1.0.tgz", + "integrity": "sha512-TYOanM3wGwNGsZN2cVTYPArw454xnXj5qmWF1bEoAc4+cU/ol7GVh7odevjp1FNHduHc3KZMcFduxU5Xc6uJRQ==", + "dev": true, + "dependencies": { + "yocto-queue": "^0.1.0" + }, + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/jest-circus/node_modules/yocto-queue": { + "version": "0.1.0", + "resolved": "https://registry.npmjs.org/yocto-queue/-/yocto-queue-0.1.0.tgz", + "integrity": "sha512-rVksvsnNCdJ/ohGc6xgPwyN8eheCxsiLM8mxuE/t/mOVqJewPuO1miLpTHQiRgTKCLexL4MeAFVagts7HmNZ2Q==", + "dev": true, + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, "node_modules/jest-cli": { "version": "29.7.0", "resolved": "https://registry.npmjs.org/jest-cli/-/jest-cli-29.7.0.tgz", @@ -5694,6 +5749,33 @@ "node": "^14.15.0 || ^16.10.0 || >=18.0.0" } }, + "node_modules/jest-runner/node_modules/p-limit": { + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/p-limit/-/p-limit-3.1.0.tgz", + "integrity": "sha512-TYOanM3wGwNGsZN2cVTYPArw454xnXj5qmWF1bEoAc4+cU/ol7GVh7odevjp1FNHduHc3KZMcFduxU5Xc6uJRQ==", + "dev": true, + "dependencies": { + "yocto-queue": "^0.1.0" + }, + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/jest-runner/node_modules/yocto-queue": { + "version": "0.1.0", + "resolved": "https://registry.npmjs.org/yocto-queue/-/yocto-queue-0.1.0.tgz", + "integrity": "sha512-rVksvsnNCdJ/ohGc6xgPwyN8eheCxsiLM8mxuE/t/mOVqJewPuO1miLpTHQiRgTKCLexL4MeAFVagts7HmNZ2Q==", + "dev": true, + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, "node_modules/jest-runtime": { "version": "29.7.0", "resolved": "https://registry.npmjs.org/jest-runtime/-/jest-runtime-29.7.0.tgz", @@ -6446,6 +6528,35 @@ } }, "node_modules/p-limit": { + "version": "6.1.0", + "resolved": "https://registry.npmjs.org/p-limit/-/p-limit-6.1.0.tgz", + "integrity": "sha512-H0jc0q1vOzlEk0TqAKXKZxdl7kX3OFUzCnNVUnq5Pc3DGo0kpeaMuPqxQn235HibwBEb0/pm9dgKTjXy66fBkg==", + "dependencies": { + "yocto-queue": "^1.1.1" + }, + "engines": { + "node": ">=18" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/p-locate": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/p-locate/-/p-locate-5.0.0.tgz", + "integrity": "sha512-LaNjtRWUBY++zB5nE/NwcaoMylSPk+S+ZHNB1TzdbMJMny6dynpAGt7X/tl/QYq3TIeE6nxHppbo2LGymrG5Pw==", + "dev": true, + "dependencies": { + "p-limit": "^3.0.2" + }, + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/p-locate/node_modules/p-limit": { "version": "3.1.0", "resolved": "https://registry.npmjs.org/p-limit/-/p-limit-3.1.0.tgz", "integrity": "sha512-TYOanM3wGwNGsZN2cVTYPArw454xnXj5qmWF1bEoAc4+cU/ol7GVh7odevjp1FNHduHc3KZMcFduxU5Xc6uJRQ==", @@ -6460,14 +6571,11 @@ "url": "https://github.com/sponsors/sindresorhus" } }, - "node_modules/p-locate": { - "version": "5.0.0", - "resolved": "https://registry.npmjs.org/p-locate/-/p-locate-5.0.0.tgz", - "integrity": "sha512-LaNjtRWUBY++zB5nE/NwcaoMylSPk+S+ZHNB1TzdbMJMny6dynpAGt7X/tl/QYq3TIeE6nxHppbo2LGymrG5Pw==", + "node_modules/p-locate/node_modules/yocto-queue": { + "version": "0.1.0", + "resolved": "https://registry.npmjs.org/yocto-queue/-/yocto-queue-0.1.0.tgz", + "integrity": "sha512-rVksvsnNCdJ/ohGc6xgPwyN8eheCxsiLM8mxuE/t/mOVqJewPuO1miLpTHQiRgTKCLexL4MeAFVagts7HmNZ2Q==", "dev": true, - "dependencies": { - "p-limit": "^3.0.2" - }, "engines": { "node": ">=10" }, @@ -8113,12 +8221,11 @@ } }, "node_modules/yocto-queue": { - "version": "0.1.0", - "resolved": "https://registry.npmjs.org/yocto-queue/-/yocto-queue-0.1.0.tgz", - "integrity": "sha512-rVksvsnNCdJ/ohGc6xgPwyN8eheCxsiLM8mxuE/t/mOVqJewPuO1miLpTHQiRgTKCLexL4MeAFVagts7HmNZ2Q==", - "dev": true, + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/yocto-queue/-/yocto-queue-1.1.1.tgz", + "integrity": "sha512-b4JR1PFR10y1mKjhHY9LaGo6tmrgjit7hxVIeAmyMw3jegXR4dhYqLaQF5zMXZxY7tLpMyJeLjr1C4rLmkVe8g==", "engines": { - "node": ">=10" + "node": ">=12.20" }, "funding": { "url": "https://github.com/sponsors/sindresorhus" diff --git a/package.json b/package.json index 0415f1c..278b02a 100644 --- a/package.json +++ b/package.json @@ -34,6 +34,7 @@ "@octokit/core": "^4.2.4", "@octokit/plugin-paginate-rest": "^5.0.1", "@octokit/plugin-rest-endpoint-methods": "^6.8.1", + "p-limit": "^6.1.0", "proxy-from-env": "^1.1.0", "undici": "^6.19.8", "uuid": "^9.0.1" diff --git a/src/github-helper.ts b/src/github-helper.ts index ca23961..a364151 100644 --- a/src/github-helper.ts +++ b/src/github-helper.ts @@ -2,11 +2,14 @@ import * as core from '@actions/core' import {Inputs} from './create-pull-request' import {Commit} from './git-command-manager' import {Octokit, OctokitOptions} from './octokit-client' +import pLimit from 'p-limit' import * as utils from './utils' const ERROR_PR_REVIEW_TOKEN_SCOPE = 'Validation Failed: "Could not resolve to a node with the global id of' +const blobCreationLimit = pLimit(8) + interface Repository { owner: string repo: string @@ -227,11 +230,13 @@ export class GitHubHelper { let sha: string | null = null if (status === 'A' || status === 'M') { core.info(`Creating blob for file '${path}'`) - const {data: blob} = await this.octokit.rest.git.createBlob({ - ...repository, - content: utils.readFileBase64([repoPath, path]), - encoding: 'base64' - }) + const {data: blob} = await blobCreationLimit(() => + this.octokit.rest.git.createBlob({ + ...repository, + content: utils.readFileBase64([repoPath, path]), + encoding: 'base64' + }) + ) sha = blob.sha } return {