From 4f251bc90f192330ff3a57dd495d33c8cfad30b9 Mon Sep 17 00:00:00 2001 From: SyncIt21 <110812394+SyncIt21@users.noreply.github.com> Date: Mon, 6 Jul 2026 18:10:48 +0530 Subject: [PATCH 1/5] Updates & Fixes --- dist/index.js | 212 +++++++++++++++++++++++++++++++++------------- package-lock.json | 211 ++++++++++++++++++++++----------------------- package.json | 14 +-- src/index.ts | 87 ++++++++++--------- 4 files changed, 308 insertions(+), 216 deletions(-) diff --git a/dist/index.js b/dist/index.js index ab3778f..07340f7 100644 --- a/dist/index.js +++ b/dist/index.js @@ -2691,6 +2691,7 @@ function requireDispatcherBase () { get webSocketOptions () { return { + maxFragments: this[kWebSocketOptions].maxFragments ?? 131072, maxPayloadSize: this[kWebSocketOptions].maxPayloadSize ?? 128 * 1024 * 1024 } } @@ -8642,6 +8643,9 @@ function requireClientH1 () { const FastBuffer = Buffer[Symbol.species]; const addListener = util.addListener; const removeAllListeners = util.removeAllListeners; + const kIdleSocketValidation = Symbol('kIdleSocketValidation'); + const kIdleSocketValidationTimeout = Symbol('kIdleSocketValidationTimeout'); + const kSocketUsed = Symbol('kSocketUsed'); let extractBody; @@ -8956,6 +8960,11 @@ function requireClientH1 () { return -1 } + if (client[kRunning] === 0) { + util.destroy(socket, new SocketError('bad response', util.getSocketInfo(socket))); + return -1 + } + const request = client[kQueue][client[kRunningIdx]]; if (!request) { return -1 @@ -9059,6 +9068,11 @@ function requireClientH1 () { return -1 } + if (client[kRunning] === 0) { + util.destroy(socket, new SocketError('bad response', util.getSocketInfo(socket))); + return -1 + } + const request = client[kQueue][client[kRunningIdx]]; /* istanbul ignore next: difficult to make a test case for */ @@ -9232,6 +9246,7 @@ function requireClientH1 () { request.onComplete(headers); client[kQueue][client[kRunningIdx]++] = null; + socket[kSocketUsed] = true; if (socket[kWriting]) { assert(client[kRunning] === 0); @@ -9290,6 +9305,9 @@ function requireClientH1 () { socket[kWriting] = false; socket[kReset] = false; socket[kBlocking] = false; + socket[kIdleSocketValidation] = 0; + socket[kIdleSocketValidationTimeout] = null; + socket[kSocketUsed] = false; socket[kParser] = new Parser(client, socket, llhttpInstance); addListener(socket, 'error', function (err) { @@ -9336,6 +9354,8 @@ function requireClientH1 () { const client = this[kClient]; const parser = this[kParser]; + clearIdleSocketValidation(this); + if (parser) { if (!this[kError] && parser.statusCode && !parser.shouldKeepAlive) { this[kError] = parser.finish() || this[kError]; @@ -9401,7 +9421,7 @@ function requireClientH1 () { return socket.destroyed }, busy (request) { - if (socket[kWriting] || socket[kReset] || socket[kBlocking]) { + if (socket[kWriting] || socket[kReset] || socket[kBlocking] || socket[kIdleSocketValidation] === 1) { return true } @@ -9439,6 +9459,31 @@ function requireClientH1 () { } } + function clearIdleSocketValidation (socket) { + if (socket[kIdleSocketValidationTimeout]) { + clearTimeout(socket[kIdleSocketValidationTimeout]); + socket[kIdleSocketValidationTimeout] = null; + } + + socket[kIdleSocketValidation] = 0; + } + + function scheduleIdleSocketValidation (client, socket) { + socket[kIdleSocketValidation] = 1; + socket[kIdleSocketValidationTimeout] = setTimeout(() => { + socket[kIdleSocketValidationTimeout] = null; + socket[kIdleSocketValidation] = 2; + + if (client[kSocket] === socket && !socket.destroyed) { + client[kResume](); + } + }, 0); + socket[kIdleSocketValidationTimeout].unref?.(); + } + + /** + * @param {import('./client.js')} client + */ function resumeH1 (client) { const socket = client[kSocket]; @@ -9453,6 +9498,32 @@ function requireClientH1 () { socket[kNoRef] = false; } + if (client[kRunning] === 0 && client[kPending] > 0 && socket[kSocketUsed]) { + if (socket[kIdleSocketValidation] === 0) { + scheduleIdleSocketValidation(client, socket); + socket[kParser].readMore(); + if (socket.destroyed) { + return + } + return + } + + if (socket[kIdleSocketValidation] === 1) { + socket[kParser].readMore(); + if (socket.destroyed) { + return + } + return + } + } + + if (client[kRunning] === 0) { + socket[kParser].readMore(); + if (socket.destroyed) { + return + } + } + if (client[kSize] === 0) { if (socket[kParser].timeoutType !== TIMEOUT_KEEP_ALIVE) { socket[kParser].setTimeout(client[kKeepAliveTimeoutValue], TIMEOUT_KEEP_ALIVE); @@ -9546,6 +9617,7 @@ function requireClientH1 () { } const socket = client[kSocket]; + clearIdleSocketValidation(socket); const abort = (err) => { if (request.aborted || request.completed) { @@ -24028,32 +24100,25 @@ function requireParse () { // If the attribute-name case-insensitively matches the string // "SameSite", the user agent MUST process the cookie-av as follows: - // 1. Let enforcement be "Default". - let enforcement = 'Default'; - const attributeValueLowercase = attributeValue.toLowerCase(); - // 2. If cookie-av's attribute-value is a case-insensitive match for - // "None", set enforcement to "None". - if (attributeValueLowercase.includes('none')) { - enforcement = 'None'; - } - - // 3. If cookie-av's attribute-value is a case-insensitive match for - // "Strict", set enforcement to "Strict". - if (attributeValueLowercase.includes('strict')) { - enforcement = 'Strict'; - } - // 4. If cookie-av's attribute-value is a case-insensitive match for - // "Lax", set enforcement to "Lax". - if (attributeValueLowercase.includes('lax')) { - enforcement = 'Lax'; + // 1. If cookie-av's attribute-value is a case-insensitive match for + // "None", append an attribute to the cookie-attribute-list with an + // attribute-name of "SameSite" and an attribute-value of "None". + if (attributeValueLowercase === 'none') { + cookieAttributeList.sameSite = 'None'; + } else if (attributeValueLowercase === 'strict') { + // 2. If cookie-av's attribute-value is a case-insensitive match for + // "Strict", append an attribute to the cookie-attribute-list with + // an attribute-name of "SameSite" and an attribute-value of + // "Strict". + cookieAttributeList.sameSite = 'Strict'; + } else if (attributeValueLowercase === 'lax') { + // 3. If cookie-av's attribute-value is a case-insensitive match for + // "Lax", append an attribute to the cookie-attribute-list with an + // attribute-name of "SameSite" and an attribute-value of "Lax". + cookieAttributeList.sameSite = 'Lax'; } - - // 5. Append an attribute to the cookie-attribute-list with an - // attribute-name of "SameSite" and an attribute-value of - // enforcement. - cookieAttributeList.sameSite = enforcement; } else { cookieAttributeList.unparsed ??= []; @@ -25639,6 +25704,11 @@ function requireReceiver () { const { PerMessageDeflate } = requirePermessageDeflate(); const { MessageSizeExceededError } = requireErrors(); + function failWebsocketConnectionWithCode (ws, code, reason) { + closeWebSocketConnection(ws, code, reason, Buffer.byteLength(reason)); + failWebsocketConnection(ws, reason); + } + // This code was influenced by ws released under the MIT license. // Copyright (c) 2011 Einar Otto Stangvik // Copyright (c) 2013 Arnout Kazemier and contributors @@ -25658,19 +25728,23 @@ function requireReceiver () { /** @type {Map} */ #extensions + /** @type {number} */ + #maxFragments + /** @type {number} */ #maxPayloadSize /** * @param {import('./websocket').WebSocket} ws * @param {Map|null} extensions - * @param {{ maxPayloadSize?: number }} [options] + * @param {{ maxFragments?: number, maxPayloadSize?: number }} [options] */ constructor (ws, extensions, options = {}) { super(); this.ws = ws; this.#extensions = extensions == null ? new Map() : extensions; + this.#maxFragments = options.maxFragments ?? 0; this.#maxPayloadSize = options.maxPayloadSize ?? 0; if (this.#extensions.has('permessage-deflate')) { @@ -25694,9 +25768,9 @@ function requireReceiver () { if ( this.#maxPayloadSize > 0 && !isControlFrame(this.#info.opcode) && - this.#info.payloadLength > this.#maxPayloadSize + this.#info.payloadLength + this.#fragmentsBytes > this.#maxPayloadSize ) { - failWebsocketConnection(this.ws, 'Payload size exceeds maximum allowed size'); + failWebsocketConnectionWithCode(this.ws, 1009, 'Payload size exceeds maximum allowed size'); return false } @@ -25861,10 +25935,12 @@ function requireReceiver () { this.#state = parserStates.INFO; } else { if (!this.#info.compressed) { - this.writeFragments(body); + if (!this.writeFragments(body)) { + return + } if (this.#maxPayloadSize > 0 && this.#fragmentsBytes > this.#maxPayloadSize) { - failWebsocketConnection(this.ws, new MessageSizeExceededError().message); + failWebsocketConnectionWithCode(this.ws, 1009, new MessageSizeExceededError().message); return } @@ -25883,14 +25959,17 @@ function requireReceiver () { this.#info.fin, (error, data) => { if (error) { - failWebsocketConnection(this.ws, error.message); + const code = error instanceof MessageSizeExceededError ? 1009 : 1007; + failWebsocketConnectionWithCode(this.ws, code, error.message); return } - this.writeFragments(data); + if (!this.writeFragments(data)) { + return + } if (this.#maxPayloadSize > 0 && this.#fragmentsBytes > this.#maxPayloadSize) { - failWebsocketConnection(this.ws, new MessageSizeExceededError().message); + failWebsocketConnectionWithCode(this.ws, 1009, new MessageSizeExceededError().message); return } @@ -25960,8 +26039,17 @@ function requireReceiver () { } writeFragments (fragment) { + if ( + this.#maxFragments > 0 && + this.#fragments.length === this.#maxFragments + ) { + failWebsocketConnectionWithCode(this.ws, 1008, 'Too many message fragments'); + return false + } + this.#fragmentsBytes += fragment.length; this.#fragments.push(fragment); + return true } consumeFragments () { @@ -26664,9 +26752,12 @@ function requireWebsocket () { // once this happens, the connection is open this[kResponse] = response; - const maxPayloadSize = this[kController]?.dispatcher?.webSocketOptions?.maxPayloadSize; + const webSocketOptions = this[kController]?.dispatcher?.webSocketOptions; + const maxFragments = webSocketOptions?.maxFragments; + const maxPayloadSize = webSocketOptions?.maxPayloadSize; const parser = new ByteParser(this, parsedExtensions, { + maxFragments, maxPayloadSize }); parser.on('drain', onParserDrain); @@ -30027,7 +30118,7 @@ class RequestError extends Error { // pkg/dist-src/index.js // pkg/dist-src/version.js -var VERSION$4 = "10.0.10"; +var VERSION$4 = "10.0.11"; // pkg/dist-src/defaults.js var defaults_default = { @@ -30177,9 +30268,10 @@ function toErrorMessage(data) { if (data instanceof ArrayBuffer) { return "Unknown error"; } - if ("message" in data) { - const suffix = "documentation_url" in data ? ` - ${data.documentation_url}` : ""; - return Array.isArray(data.errors) ? `${data.message}: ${data.errors.map((v) => JSON.stringify(v)).join(", ")}${suffix}` : `${data.message}${suffix}`; + if (typeof data === "object" && data !== null && "message" in data) { + const objectData = data; + const suffix = "documentation_url" in objectData ? ` - ${objectData.documentation_url}` : ""; + return Array.isArray(objectData.errors) ? `${objectData.message}: ${objectData.errors.map((v) => JSON.stringify(v)).join(", ")}${suffix}` : `${objectData.message}${suffix}`; } return `Unknown error: ${JSON.stringify(data)}`; } @@ -33111,8 +33203,8 @@ function getOctokit(token, options, ...additionalPlugins) { return new GitHubWithPlugins(getOctokitOptions(token)); } -//Maximum amount of files to process, PRs with more files will not be processed. -const FILE_LIMIT = 1000; +//Maximum amount of files to process per page. +const FILES_PER_PAGE = 300; //Returns a map of file path -> list of owners function ParseCodeownersFile(filePath) { const codeowners = new Map(); @@ -33138,11 +33230,12 @@ function ParseCodeownersFile(filePath) { return codeowners; } //Returns the list of owners to notify from the list of modified files -function GetOwnersWithModifiedFiles(codeowners, modifiedFiles) { - const regex_files = new Map(); - const owners = new Set(); +function GetOwnersWithModifiedFiles(codeowners, modifiedFiles, regex_files, owners) { for (const file of modifiedFiles) { for (const [owner, paths] of codeowners.entries()) { + if (owners.has(owner)) { + continue; + } for (const ownerPath of paths) { let regex_match = regex_files.get(ownerPath); if (!regex_match) { @@ -33163,7 +33256,7 @@ function GetOwnersWithModifiedFiles(codeowners, modifiedFiles) { } //add regex to registry to match this exact path if it appearas again in the file regex_match = new RegExp(regex); - regex_files.set(file, regex_match); + regex_files.set(ownerPath, regex_match); } if (file.match(regex_match)) { owners.add(owner); @@ -33171,7 +33264,6 @@ function GetOwnersWithModifiedFiles(codeowners, modifiedFiles) { } } } - return Array.from(owners); } async function run() { //# Part 1: Getting all code owners based on their modified files @@ -33188,27 +33280,25 @@ async function run() { info(`Parsing codeowner file at: ${workspace_file}`); // Get github client using the provided token const octokit = getOctokit(getInput('token')); - let response = await octokit.rest.pulls.get({ - owner: core_owner, - repo: core_repo, - pull_number: pull_number - }); - if (response.data.changed_files > FILE_LIMIT) { - setFailed(`PR has ${response.data.changed_files} files, which is more than the limit of ${FILE_LIMIT}. Skipping codeowner assignment.`); - return; - } // Parse the codeowners file and get the modified files in the PR, then get the owners with modified files const codeowners = ParseCodeownersFile(workspace_file); - const modifiedFiles = (await octokit.paginate(octokit.rest.pulls.listFiles.endpoint.merge({ + // Get all codeowners of modified files. We process each page of files and push the results onto the final list + const modifiedFilesIterator = octokit.paginate.iterator(octokit.rest.pulls.listFiles.endpoint.merge({ owner: core_owner, repo: core_repo, - pull_number: pull_number - }))) - .flatMap(modified_files => modified_files) - .map(modified_file => modified_file.filename); - const ownersWithModifiedFiles = GetOwnersWithModifiedFiles(codeowners, modifiedFiles); + pull_number: pull_number, + per_page: FILES_PER_PAGE + })); + // Push results per page onto the final array + const ownerPathRegexMap = new Map(); + const ownersWithModifiedFiles = new Set(); + for await (const page_set of modifiedFilesIterator) { + for (const page of page_set.data) { + GetOwnersWithModifiedFiles(codeowners, page.map(modified_file => modified_file.filename), ownerPathRegexMap, ownersWithModifiedFiles); + } + } // Display all code owners - info(`Owners With Modified Files: ${ownersWithModifiedFiles.join(' ')}`); + info(`Owners With Modified Files: ${ownersWithModifiedFiles.values().toArray().join(' ')}`); //# Part 2: Requesting reviews based on owners listed above const trimmed_owners = []; //Remove the @ symbol at the start of every owner name @@ -33216,7 +33306,7 @@ async function run() { trimmed_owners.push(owner.replace('@', '')); } //Remove PR author from the user list - const index = trimmed_owners.indexOf(response.data.user.login); + const index = trimmed_owners.indexOf(context.payload.pull_request?.user.login); if (index >= 0) { trimmed_owners.splice(index, 1); } diff --git a/package-lock.json b/package-lock.json index b2cdda8..808bc32 100644 --- a/package-lock.json +++ b/package-lock.json @@ -16,16 +16,16 @@ "devDependencies": { "@eslint/eslintrc": "^3.3.5", "@eslint/js": "^10.0.1", - "@octokit/plugin-rest-endpoint-methods": "^17.0.0", + "@octokit/plugin-paginate-rest": "^14.0.0", "@rollup/plugin-commonjs": "^29.0.3", "@rollup/plugin-node-resolve": "^16.0.3", "@stylistic/eslint-plugin": "^5.10.0", - "@types/node": "^25.9.1", - "@typescript-eslint/eslint-plugin": "^8.59.1", - "@typescript-eslint/parser": "^8.59.1", - "eslint": "^10.4.1", - "globals": "^17.6.0", - "prettier": "^3.8.3", + "@types/node": "^26.1.0", + "@typescript-eslint/eslint-plugin": "^8.62.1", + "@typescript-eslint/parser": "^8.62.1", + "eslint": "^10.6.0", + "globals": "^17.7.0", + "prettier": "^3.9.4", "typescript": "^6.0.3" } }, @@ -157,9 +157,9 @@ } }, "node_modules/@eslint/config-array/node_modules/brace-expansion": { - "version": "5.0.6", - "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-5.0.6.tgz", - "integrity": "sha512-kLpxurY4Z4r9sgMsyG0Z9uzsBlgiU/EFKhj/h91/8yHu0edo7XuixOIH3VcJ8kkxs6/jPzoI6U9Vj3WqbMQ94g==", + "version": "5.0.7", + "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-5.0.7.tgz", + "integrity": "sha512-7oFy703dxfY3/NLxC1fh2SUCQ0H9rmAY+5EpDVfXjUTTs+HEwR2nYaqLv+GWcTsumwxPfiz6CzCNkwXwBUwqCA==", "dev": true, "license": "MIT", "dependencies": { @@ -457,9 +457,9 @@ } }, "node_modules/@octokit/request": { - "version": "10.0.10", - "resolved": "https://registry.npmjs.org/@octokit/request/-/request-10.0.10.tgz", - "integrity": "sha512-KxNC2pTqqhszMNrf12ZRd4PonRgyJdsM4F/jySiddQK+DsRcfBtUvqn8t7UsyZhnRJHvX46OohDt5N3VqIWC2w==", + "version": "10.0.11", + "resolved": "https://registry.npmjs.org/@octokit/request/-/request-10.0.11.tgz", + "integrity": "sha512-+s7HUxjfFqOMS9VlIwDffq0MikjSAK0gSpG73W+meAvVAvX4MBrHYTK5Bj3Uot55qFT4gzUtfzE4mGWY4Br8/Q==", "license": "MIT", "dependencies": { "@octokit/endpoint": "^11.0.3", @@ -612,13 +612,13 @@ "license": "MIT" }, "node_modules/@types/node": { - "version": "25.9.1", - "resolved": "https://registry.npmjs.org/@types/node/-/node-25.9.1.tgz", - "integrity": "sha512-xfrlY7UD5rMJk3ZVJP8BNzS28J36YJg+xp+LPXV1TdWxr8uMH5A860QNxYDGQe/ylDSgjxE52Q9VnO7p75tJxg==", + "version": "26.1.0", + "resolved": "https://registry.npmjs.org/@types/node/-/node-26.1.0.tgz", + "integrity": "sha512-O0A1G3xPGy4w7AgQdAQYUlQ+BKk2Oovw8eRpofyp5KdBZULnbe+WqaOVNrm705SHphCiG4XHsACrSmPu1f+Kgw==", "dev": true, "license": "MIT", "dependencies": { - "undici-types": ">=7.24.0 <7.24.7" + "undici-types": "~8.3.0" } }, "node_modules/@types/resolve": { @@ -629,17 +629,17 @@ "license": "MIT" }, "node_modules/@typescript-eslint/eslint-plugin": { - "version": "8.60.1", - "resolved": "https://registry.npmjs.org/@typescript-eslint/eslint-plugin/-/eslint-plugin-8.60.1.tgz", - "integrity": "sha512-JQ4S5GB0tfjO8BuJ4fcX+HodkzJjYBV+7OJ+wLygaX7OGQ7FudyHL4NSCA6ob+w3Yn+5MkKIozOwQhXeM7opVg==", + "version": "8.62.1", + "resolved": "https://registry.npmjs.org/@typescript-eslint/eslint-plugin/-/eslint-plugin-8.62.1.tgz", + "integrity": "sha512-4EQM77WgVNxj7OkL/5b/D/xZsw00G577+UriYTC7JF5opcF3T2AuoeY7ueLaZgSVjSgCS6yOAJB5bRGLPSJUzA==", "dev": true, "license": "MIT", "dependencies": { "@eslint-community/regexpp": "^4.12.2", - "@typescript-eslint/scope-manager": "8.60.1", - "@typescript-eslint/type-utils": "8.60.1", - "@typescript-eslint/utils": "8.60.1", - "@typescript-eslint/visitor-keys": "8.60.1", + "@typescript-eslint/scope-manager": "8.62.1", + "@typescript-eslint/type-utils": "8.62.1", + "@typescript-eslint/utils": "8.62.1", + "@typescript-eslint/visitor-keys": "8.62.1", "ignore": "^7.0.5", "natural-compare": "^1.4.0", "ts-api-utils": "^2.5.0" @@ -652,7 +652,7 @@ "url": "https://opencollective.com/typescript-eslint" }, "peerDependencies": { - "@typescript-eslint/parser": "^8.60.1", + "@typescript-eslint/parser": "^8.62.1", "eslint": "^8.57.0 || ^9.0.0 || ^10.0.0", "typescript": ">=4.8.4 <6.1.0" } @@ -668,16 +668,16 @@ } }, "node_modules/@typescript-eslint/parser": { - "version": "8.60.1", - "resolved": "https://registry.npmjs.org/@typescript-eslint/parser/-/parser-8.60.1.tgz", - "integrity": "sha512-A0M6ua6H252bVjPvvtSgl2QA4+ET9S5Mtkb2GDyTxIhH/C4qDItT7RQNO5PhMC6NXGYXOR9dIalcDDgBKT7oFA==", + "version": "8.62.1", + "resolved": "https://registry.npmjs.org/@typescript-eslint/parser/-/parser-8.62.1.tgz", + "integrity": "sha512-sPhE4iHuJDSvoAiec+Ro8JyXw8f0ql13HFR82P99nCm9GwTEKG0KYLvDe6REk8BCXuit6vJAv/Yxg5ABaNS2rA==", "dev": true, "license": "MIT", "dependencies": { - "@typescript-eslint/scope-manager": "8.60.1", - "@typescript-eslint/types": "8.60.1", - "@typescript-eslint/typescript-estree": "8.60.1", - "@typescript-eslint/visitor-keys": "8.60.1", + "@typescript-eslint/scope-manager": "8.62.1", + "@typescript-eslint/types": "8.62.1", + "@typescript-eslint/typescript-estree": "8.62.1", + "@typescript-eslint/visitor-keys": "8.62.1", "debug": "^4.4.3" }, "engines": { @@ -693,14 +693,14 @@ } }, "node_modules/@typescript-eslint/project-service": { - "version": "8.60.1", - "resolved": "https://registry.npmjs.org/@typescript-eslint/project-service/-/project-service-8.60.1.tgz", - "integrity": "sha512-eXkTH2bxmXlqD1RnOPmLZ9ZM9D3VwSx04JOwBnP9RQ+yUA5a2Mu7SfW8uaV2Aon53NJzZlZYuX7tn91Izf+xaw==", + "version": "8.62.1", + "resolved": "https://registry.npmjs.org/@typescript-eslint/project-service/-/project-service-8.62.1.tgz", + "integrity": "sha512-yQ3RgY5RkSBpsNS1Bx/JQEcA24FOSdfGktoyprAr5u18390UQdtVcfnEv4nIrIshNnavlVyZBKxQwT1fIAE6cg==", "dev": true, "license": "MIT", "dependencies": { - "@typescript-eslint/tsconfig-utils": "^8.60.1", - "@typescript-eslint/types": "^8.60.1", + "@typescript-eslint/tsconfig-utils": "^8.62.1", + "@typescript-eslint/types": "^8.62.1", "debug": "^4.4.3" }, "engines": { @@ -715,14 +715,14 @@ } }, "node_modules/@typescript-eslint/scope-manager": { - "version": "8.60.1", - "resolved": "https://registry.npmjs.org/@typescript-eslint/scope-manager/-/scope-manager-8.60.1.tgz", - "integrity": "sha512-gvI5OQoptnxQnchOirukCuQ55svJSTuD/4k5+pC267xyBtYry748R9/c3tYUzb/iE6RZfllRz2lVulLCHkTm4w==", + "version": "8.62.1", + "resolved": "https://registry.npmjs.org/@typescript-eslint/scope-manager/-/scope-manager-8.62.1.tgz", + "integrity": "sha512-r4d249KbQ1SFdpeStvob8Ih6aPPIzfqllPVOtvhve6ZcpuVcYo5/7zUWckKpHE7StASX4kTKZTLf0WQm/wPkcg==", "dev": true, "license": "MIT", "dependencies": { - "@typescript-eslint/types": "8.60.1", - "@typescript-eslint/visitor-keys": "8.60.1" + "@typescript-eslint/types": "8.62.1", + "@typescript-eslint/visitor-keys": "8.62.1" }, "engines": { "node": "^18.18.0 || ^20.9.0 || >=21.1.0" @@ -733,9 +733,9 @@ } }, "node_modules/@typescript-eslint/tsconfig-utils": { - "version": "8.60.1", - "resolved": "https://registry.npmjs.org/@typescript-eslint/tsconfig-utils/-/tsconfig-utils-8.60.1.tgz", - "integrity": "sha512-nh8w4qAteiKuZu3pSSzG/yGKpw0OlkrKnzFmbVRenKaD4qc+7i1GrmZaLVkr8rk4uipiPGMOW4YsM6WmKZ5CvA==", + "version": "8.62.1", + "resolved": "https://registry.npmjs.org/@typescript-eslint/tsconfig-utils/-/tsconfig-utils-8.62.1.tgz", + "integrity": "sha512-xadytJqX9vJVQ2fdQjkcIVigwaOJNWkpjdLt6cEQ+xPnrI1fkp+/jZE/I97k9KUjqtpd25i0HeyZf3T6dutv2g==", "dev": true, "license": "MIT", "engines": { @@ -750,15 +750,15 @@ } }, "node_modules/@typescript-eslint/type-utils": { - "version": "8.60.1", - "resolved": "https://registry.npmjs.org/@typescript-eslint/type-utils/-/type-utils-8.60.1.tgz", - "integrity": "sha512-sdwTrpjosW7ANQYJ39ZBF1ZyEMEGVB2UsikrserVM/30a/F1dTLnu9bGxEdosugyu5caigjLrR2qiD11asjI1A==", + "version": "8.62.1", + "resolved": "https://registry.npmjs.org/@typescript-eslint/type-utils/-/type-utils-8.62.1.tgz", + "integrity": "sha512-aXM5xlqXiTxPibXB93cLAURfT3rlizf7uMXISCXy66Isr/9hISJx3yDsKl0L7lKa51b8JpFuNKby0/O0pEm9jg==", "dev": true, "license": "MIT", "dependencies": { - "@typescript-eslint/types": "8.60.1", - "@typescript-eslint/typescript-estree": "8.60.1", - "@typescript-eslint/utils": "8.60.1", + "@typescript-eslint/types": "8.62.1", + "@typescript-eslint/typescript-estree": "8.62.1", + "@typescript-eslint/utils": "8.62.1", "debug": "^4.4.3", "ts-api-utils": "^2.5.0" }, @@ -775,9 +775,9 @@ } }, "node_modules/@typescript-eslint/types": { - "version": "8.60.1", - "resolved": "https://registry.npmjs.org/@typescript-eslint/types/-/types-8.60.1.tgz", - "integrity": "sha512-4h0tY8ppCkdCzcrl2YM5M3my0xsE1Tf8om3owEu5oPWmXwkKRmk0j0LGDzYBGUcAlesEbxBhazqu/K4cu3Ug7w==", + "version": "8.62.1", + "resolved": "https://registry.npmjs.org/@typescript-eslint/types/-/types-8.62.1.tgz", + "integrity": "sha512-ooCzJFaf+Hg+uG6fA3NRFGuFjlfNlDhBthbv4ZPU/0elCAFUfnyXUvf/WOpHz/jYwSmvU2GkR2LtyUfy1AxZ1Q==", "dev": true, "license": "MIT", "engines": { @@ -789,16 +789,16 @@ } }, "node_modules/@typescript-eslint/typescript-estree": { - "version": "8.60.1", - "resolved": "https://registry.npmjs.org/@typescript-eslint/typescript-estree/-/typescript-estree-8.60.1.tgz", - "integrity": "sha512-alpRkfG8hlVE5kdJW2GkfgDgXxold3e8e4l6EnmhRmRLbekgAPCCGDVD++sABy9FcgPFroq+uFcCSM1vR57Cew==", + "version": "8.62.1", + "resolved": "https://registry.npmjs.org/@typescript-eslint/typescript-estree/-/typescript-estree-8.62.1.tgz", + "integrity": "sha512-xMcW9oP9u7fAMXYs9A65CVmtLQe2r//oXINHfi8HV+oiqhih17sbLdhXr4540YWlgpDKQdY854OL5ZrdCiQsAA==", "dev": true, "license": "MIT", "dependencies": { - "@typescript-eslint/project-service": "8.60.1", - "@typescript-eslint/tsconfig-utils": "8.60.1", - "@typescript-eslint/types": "8.60.1", - "@typescript-eslint/visitor-keys": "8.60.1", + "@typescript-eslint/project-service": "8.62.1", + "@typescript-eslint/tsconfig-utils": "8.62.1", + "@typescript-eslint/types": "8.62.1", + "@typescript-eslint/visitor-keys": "8.62.1", "debug": "^4.4.3", "minimatch": "^10.2.2", "semver": "^7.7.3", @@ -827,9 +827,9 @@ } }, "node_modules/@typescript-eslint/typescript-estree/node_modules/brace-expansion": { - "version": "5.0.6", - "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-5.0.6.tgz", - "integrity": "sha512-kLpxurY4Z4r9sgMsyG0Z9uzsBlgiU/EFKhj/h91/8yHu0edo7XuixOIH3VcJ8kkxs6/jPzoI6U9Vj3WqbMQ94g==", + "version": "5.0.7", + "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-5.0.7.tgz", + "integrity": "sha512-7oFy703dxfY3/NLxC1fh2SUCQ0H9rmAY+5EpDVfXjUTTs+HEwR2nYaqLv+GWcTsumwxPfiz6CzCNkwXwBUwqCA==", "dev": true, "license": "MIT", "dependencies": { @@ -856,16 +856,16 @@ } }, "node_modules/@typescript-eslint/utils": { - "version": "8.60.1", - "resolved": "https://registry.npmjs.org/@typescript-eslint/utils/-/utils-8.60.1.tgz", - "integrity": "sha512-h2MPBLoNtjc3qZWfY3Tl51yPorQ2McHn8pJfcMNTcIvrrZrr90Ykffit0yjrPFWQcRcUxzH20+6OcVdW4yHtUg==", + "version": "8.62.1", + "resolved": "https://registry.npmjs.org/@typescript-eslint/utils/-/utils-8.62.1.tgz", + "integrity": "sha512-sHtbPfuKNZCG+ih8SyjjucqRntSVmp8XgL5u6o9mAhiSn8ds5o/M/XdM0abweme2Tln3szOstOrZ9OXitvPh0g==", "dev": true, "license": "MIT", "dependencies": { "@eslint-community/eslint-utils": "^4.9.1", - "@typescript-eslint/scope-manager": "8.60.1", - "@typescript-eslint/types": "8.60.1", - "@typescript-eslint/typescript-estree": "8.60.1" + "@typescript-eslint/scope-manager": "8.62.1", + "@typescript-eslint/types": "8.62.1", + "@typescript-eslint/typescript-estree": "8.62.1" }, "engines": { "node": "^18.18.0 || ^20.9.0 || >=21.1.0" @@ -880,13 +880,13 @@ } }, "node_modules/@typescript-eslint/visitor-keys": { - "version": "8.60.1", - "resolved": "https://registry.npmjs.org/@typescript-eslint/visitor-keys/-/visitor-keys-8.60.1.tgz", - "integrity": "sha512-EbGRQg4FhrmwLodl+t3JNAnXHWVr9Vp+Zl1QBZVPY4ByfkzIT8cX3K6QWODHtkIZqqJVEWvhHSx3v5PDHsaQag==", + "version": "8.62.1", + "resolved": "https://registry.npmjs.org/@typescript-eslint/visitor-keys/-/visitor-keys-8.62.1.tgz", + "integrity": "sha512-4g3BLxfdTMy8iZG0MaBkadnlRrCJ74cQiFbyEVMrkwIoqdyaXXQM22cotDvrl4x28wgIZ9rEJRoM+mmhSJpJ1g==", "dev": true, "license": "MIT", "dependencies": { - "@typescript-eslint/types": "8.60.1", + "@typescript-eslint/types": "8.62.1", "eslint-visitor-keys": "^5.0.0" }, "engines": { @@ -911,9 +911,9 @@ } }, "node_modules/acorn": { - "version": "8.16.0", - "resolved": "https://registry.npmjs.org/acorn/-/acorn-8.16.0.tgz", - "integrity": "sha512-UVJyE9MttOsBQIDKw1skb9nAwQuR5wuGD3+82K6JgJlm/Y+KI92oNsMNGZCYdDsVtRHSak0pcV5Dno5+4jh9sw==", + "version": "8.17.0", + "resolved": "https://registry.npmjs.org/acorn/-/acorn-8.17.0.tgz", + "integrity": "sha512-xRQbDb9BnwDafYNn6Vwl839DYVjqXYb1XVGtWAZ1kcDc6iwAL4hg3B1dZlRiuENFeO2H53gFG3in621AdERVAg==", "dev": true, "license": "MIT", "bin": { @@ -1101,11 +1101,14 @@ } }, "node_modules/eslint": { - "version": "10.4.1", - "resolved": "https://registry.npmjs.org/eslint/-/eslint-10.4.1.tgz", - "integrity": "sha512-AyIKhnOBuOAdueD7RB3xB+YeAWScb9jHsJBgH2Hcde8InP5JYhqrRR6iTMHyTEwgENK54Cp44e4v8BwNhsuHuw==", + "version": "10.6.0", + "resolved": "https://registry.npmjs.org/eslint/-/eslint-10.6.0.tgz", + "integrity": "sha512-6lVbcqSodALYo+4ELD0heG6lFiFxnLMuLkiMi2qV8LMp54N8tE8FT1GMH+ev4Ti00nFjNze2+Su6DsV5OQW3Dg==", "dev": true, "license": "MIT", + "workspaces": [ + "packages/*" + ], "dependencies": { "@eslint-community/eslint-utils": "^4.8.0", "@eslint-community/regexpp": "^4.12.2", @@ -1199,9 +1202,9 @@ } }, "node_modules/eslint/node_modules/brace-expansion": { - "version": "5.0.6", - "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-5.0.6.tgz", - "integrity": "sha512-kLpxurY4Z4r9sgMsyG0Z9uzsBlgiU/EFKhj/h91/8yHu0edo7XuixOIH3VcJ8kkxs6/jPzoI6U9Vj3WqbMQ94g==", + "version": "5.0.7", + "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-5.0.7.tgz", + "integrity": "sha512-7oFy703dxfY3/NLxC1fh2SUCQ0H9rmAY+5EpDVfXjUTTs+HEwR2nYaqLv+GWcTsumwxPfiz6CzCNkwXwBUwqCA==", "dev": true, "license": "MIT", "dependencies": { @@ -1478,9 +1481,9 @@ } }, "node_modules/globals": { - "version": "17.6.0", - "resolved": "https://registry.npmjs.org/globals/-/globals-17.6.0.tgz", - "integrity": "sha512-sepffkT8stwnIYbsMBpoCHJuJM5l98FUF2AnE07hfvE0m/qp3R586hw4jF4uadbhvg1ooIdzuu7CsfD2jzCaNA==", + "version": "17.7.0", + "resolved": "https://registry.npmjs.org/globals/-/globals-17.7.0.tgz", + "integrity": "sha512-Czmyns5dUsq4seFBR/Kdydhmo8y9kC79hiSkPn0YcGtNnYWnrgt0vjrSjx9tspoDGWm2CMarffRuLjM4xUz8xg==", "dev": true, "license": "MIT", "engines": { @@ -1604,9 +1607,9 @@ "license": "ISC" }, "node_modules/js-yaml": { - "version": "4.2.0", - "resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-4.2.0.tgz", - "integrity": "sha512-ePWsvanv0DWuDRsW8dnt+R4jQ31SCRCQ7hhNcPXZPsoBZiemuZNYGf7adZdqX2D86j6rvKp3RpCxVTSb8WQlOw==", + "version": "4.3.0", + "resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-4.3.0.tgz", + "integrity": "sha512-1td788aAnnZ5qs7V2QIRl1owjtYpbKt749Y3xauqQgwIIGF/xXWz1wMTEBx5O3LK3lXLVuqXPdPxj2BoFHaW9Q==", "dev": true, "funding": [ { @@ -1859,9 +1862,9 @@ "license": "MIT" }, "node_modules/picomatch": { - "version": "4.0.4", - "resolved": "https://registry.npmjs.org/picomatch/-/picomatch-4.0.4.tgz", - "integrity": "sha512-QP88BAKvMam/3NxH6vj2o21R6MjxZUAd6nlwAS/pnGvN9IVLocLHxGYIzFhg6fUQ+5th6P4dv4eW9jX3DSIj7A==", + "version": "4.0.5", + "resolved": "https://registry.npmjs.org/picomatch/-/picomatch-4.0.5.tgz", + "integrity": "sha512-RvwwcruNjI1ncT5xRakeyS9Lf8lcItv34KD+aif+VH9kduAyfYBipGh12274xtenIPZ119/R9BdTBa8gAwSh0A==", "dev": true, "license": "MIT", "engines": { @@ -1882,9 +1885,9 @@ } }, "node_modules/prettier": { - "version": "3.8.3", - "resolved": "https://registry.npmjs.org/prettier/-/prettier-3.8.3.tgz", - "integrity": "sha512-7igPTM53cGHMW8xWuVTydi2KO233VFiTNyF5hLJqpilHfmn8C8gPf+PS7dUT64YcXFbiMGZxS9pCSxL/Dxm/Jw==", + "version": "3.9.4", + "resolved": "https://registry.npmjs.org/prettier/-/prettier-3.9.4.tgz", + "integrity": "sha512-yWG/o/4oJfo036EKAfK6ACAoDOfHeRHx4tuxkfBZiauURiaSmYwlpOr5LQqKtIkRD2z1PLteme2WoxEnj4tHTg==", "dev": true, "license": "MIT", "bin": { @@ -1940,9 +1943,9 @@ } }, "node_modules/semver": { - "version": "7.8.1", - "resolved": "https://registry.npmjs.org/semver/-/semver-7.8.1.tgz", - "integrity": "sha512-rkVq3IXh+4FDGch+KwzX3aV9W3kO54GyEgpvBzSyctDA6Xtd7RJQV1xmXbeQp5v7+VzLOfVqiutSE6GICgPFvg==", + "version": "7.8.5", + "resolved": "https://registry.npmjs.org/semver/-/semver-7.8.5.tgz", + "integrity": "sha512-Y7/KDsb8LjooZpwaqGyulO6DQlksgCncchHGk+sZIY4SBvUocMBEFH5Ur1fI4dV+Jvl0w6cjvucaIi40puRioA==", "dev": true, "license": "ISC", "bin": { @@ -2068,18 +2071,18 @@ } }, "node_modules/undici": { - "version": "6.26.0", - "resolved": "https://registry.npmjs.org/undici/-/undici-6.26.0.tgz", - "integrity": "sha512-4yqz8a3n5HmGTlsbADNtr/dJlhkh/55Rq798G6ibiULcXbDtaLpTl1pvdqcbFfeoj3iSi52lePFM7h9H21cw/A==", + "version": "6.27.0", + "resolved": "https://registry.npmjs.org/undici/-/undici-6.27.0.tgz", + "integrity": "sha512-YmfV3YnEDzXRC5lZ2jWtWWHKGUm1zIt8AhesR1tens+HTNv+YZlN/dp6G727LOvMJ8xjP9Be7Y2Sdr96LDm+pg==", "license": "MIT", "engines": { "node": ">=18.17" } }, "node_modules/undici-types": { - "version": "7.24.6", - "resolved": "https://registry.npmjs.org/undici-types/-/undici-types-7.24.6.tgz", - "integrity": "sha512-WRNW+sJgj5OBN4/0JpHFqtqzhpbnV0GuB+OozA9gCL7a993SmU+1JBZCzLNxYsbMfIeDL+lTsphD5jN5N+n0zg==", + "version": "8.3.0", + "resolved": "https://registry.npmjs.org/undici-types/-/undici-types-8.3.0.tgz", + "integrity": "sha512-j375ScV60dom+YkPFIfTLcOiPxkN/buHz5GobjLhixFuANaNs3C9l4GmrWqejgXWJ7BbJcFYpTEUkS1Ge8bpZQ==", "dev": true, "license": "MIT" }, diff --git a/package.json b/package.json index 338aeca..df96348 100644 --- a/package.json +++ b/package.json @@ -32,16 +32,16 @@ "devDependencies": { "@eslint/eslintrc": "^3.3.5", "@eslint/js": "^10.0.1", - "@octokit/plugin-rest-endpoint-methods": "^17.0.0", + "@octokit/plugin-paginate-rest": "^14.0.0", "@rollup/plugin-commonjs": "^29.0.3", "@rollup/plugin-node-resolve": "^16.0.3", "@stylistic/eslint-plugin": "^5.10.0", - "@types/node": "^25.9.1", - "@typescript-eslint/eslint-plugin": "^8.59.1", - "@typescript-eslint/parser": "^8.59.1", - "eslint": "^10.4.1", - "globals": "^17.6.0", - "prettier": "^3.8.3", + "@types/node": "^26.1.0", + "@typescript-eslint/eslint-plugin": "^8.62.1", + "@typescript-eslint/parser": "^8.62.1", + "eslint": "^10.6.0", + "globals": "^17.7.0", + "prettier": "^3.9.4", "typescript": "^6.0.3" } } diff --git a/src/index.ts b/src/index.ts index be711e1..2bd451d 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,10 +1,10 @@ import {getInput, setFailed, info, notice} from '@actions/core' import {context, getOctokit} from '@actions/github' import {readFileSync} from 'fs' -import {RestEndpointMethodTypes} from '@octokit/plugin-rest-endpoint-methods' +import {PaginatingEndpoints} from '@octokit/plugin-paginate-rest' -//Maximum amount of files to process, PRs with more files will not be processed. -const FILE_LIMIT = 1000 +//Maximum amount of files to process per page. +const FILES_PER_PAGE = 300 //Returns a map of file path -> list of owners function ParseCodeownersFile(filePath: string): Map { @@ -42,14 +42,15 @@ function ParseCodeownersFile(filePath: string): Map { //Returns the list of owners to notify from the list of modified files function GetOwnersWithModifiedFiles( codeowners: Map, - modifiedFiles: string[] -): string[] { - const regex_files: Map = new Map() - - const owners: Set = new Set() - + modifiedFiles: string[], + regex_files: Map, + owners: Set +): void { for (const file of modifiedFiles) { for (const [owner, paths] of codeowners.entries()) { + if (owners.has(owner)) { + continue + } for (const ownerPath of paths) { let regex_match: RegExp | undefined = regex_files.get(ownerPath) if (!regex_match) { @@ -74,7 +75,7 @@ function GetOwnersWithModifiedFiles( //add regex to registry to match this exact path if it appearas again in the file regex_match = new RegExp(regex) - regex_files.set(file, regex_match) + regex_files.set(ownerPath, regex_match) } if (file.match(regex_match)) { @@ -83,8 +84,6 @@ function GetOwnersWithModifiedFiles( } } } - - return Array.from(owners) } async function run(): Promise { @@ -108,44 +107,42 @@ async function run(): Promise { getInput('token') ) - let response: RestEndpointMethodTypes['pulls']['get']['response'] = - await octokit.rest.pulls.get({ - owner: core_owner, - repo: core_repo, - pull_number: pull_number - }) - - if (response.data.changed_files > FILE_LIMIT) { - setFailed( - `PR has ${response.data.changed_files} files, which is more than the limit of ${FILE_LIMIT}. Skipping codeowner assignment.` - ) - return - } - // Parse the codeowners file and get the modified files in the PR, then get the owners with modified files const codeowners: Map = ParseCodeownersFile(workspace_file) - const modifiedFiles: string[] = ( - await octokit.paginate< - RestEndpointMethodTypes['pulls']['listFiles']['response']['data'] - >( - octokit.rest.pulls.listFiles.endpoint.merge({ - owner: core_owner, - repo: core_repo, - pull_number: pull_number - }) - ) - ) - .flatMap(modified_files => modified_files) - .map(modified_file => modified_file.filename) - const ownersWithModifiedFiles: string[] = GetOwnersWithModifiedFiles( - codeowners, - modifiedFiles + // Get all codeowners of modified files. We process each page of files and push the results onto the final list + const modifiedFilesIterator = octokit.paginate.iterator< + PaginatingEndpoints['GET /repos/{owner}/{repo}/pulls/{pull_number}/files']['response']['data'] + >( + octokit.rest.pulls.listFiles.endpoint.merge< + PaginatingEndpoints['GET /repos/{owner}/{repo}/pulls/{pull_number}/files']['parameters'] + >({ + owner: core_owner, + repo: core_repo, + pull_number: pull_number, + per_page: FILES_PER_PAGE + }) ) + // Push results per page onto the final array + const ownerPathRegexMap: Map = new Map() + const ownersWithModifiedFiles: Set = new Set() + for await (const page_set of modifiedFilesIterator) { + for (const page of page_set.data) { + GetOwnersWithModifiedFiles( + codeowners, + page.map(modified_file => modified_file.filename), + ownerPathRegexMap, + ownersWithModifiedFiles + ) + } + } + // Display all code owners - info(`Owners With Modified Files: ${ownersWithModifiedFiles.join(' ')}`) + info( + `Owners With Modified Files: ${ownersWithModifiedFiles.values().toArray().join(' ')}` + ) //# Part 2: Requesting reviews based on owners listed above const trimmed_owners: string[] = [] @@ -156,7 +153,9 @@ async function run(): Promise { } //Remove PR author from the user list - const index = trimmed_owners.indexOf(response.data.user.login) + const index = trimmed_owners.indexOf( + context.payload.pull_request?.user.login + ) if (index >= 0) { trimmed_owners.splice(index, 1) } From 2e839955db1266b4307e64c2b4d0dbff50587f5d Mon Sep 17 00:00:00 2001 From: SyncIt21 <110812394+SyncIt21@users.noreply.github.com> Date: Mon, 6 Jul 2026 18:22:20 +0530 Subject: [PATCH 2/5] even better --- dist/index.js | 6 ++++++ src/index.ts | 8 ++++++++ 2 files changed, 14 insertions(+) diff --git a/dist/index.js b/dist/index.js index 07340f7..0c0d566 100644 --- a/dist/index.js +++ b/dist/index.js @@ -33232,10 +33232,16 @@ function ParseCodeownersFile(filePath) { //Returns the list of owners to notify from the list of modified files function GetOwnersWithModifiedFiles(codeowners, modifiedFiles, regex_files, owners) { for (const file of modifiedFiles) { + //we literarly have no owners to parse so drop + if (owners.size == codeowners.size) { + return; + } for (const [owner, paths] of codeowners.entries()) { + //don't parse the same owner twice if (owners.has(owner)) { continue; } + //check if the owner owns this file for (const ownerPath of paths) { let regex_match = regex_files.get(ownerPath); if (!regex_match) { diff --git a/src/index.ts b/src/index.ts index 2bd451d..53a85aa 100644 --- a/src/index.ts +++ b/src/index.ts @@ -47,10 +47,18 @@ function GetOwnersWithModifiedFiles( owners: Set ): void { for (const file of modifiedFiles) { + //we literarly have no owners to parse so drop + if (owners.size == codeowners.size) { + return + } + for (const [owner, paths] of codeowners.entries()) { + //don't parse the same owner twice if (owners.has(owner)) { continue } + + //check if the owner owns this file for (const ownerPath of paths) { let regex_match: RegExp | undefined = regex_files.get(ownerPath) if (!regex_match) { From f31894cc39c190f9a2fcf7818f359e8246c7b781 Mon Sep 17 00:00:00 2001 From: SyncIt21 <110812394+SyncIt21@users.noreply.github.com> Date: Tue, 7 Jul 2026 09:48:36 +0530 Subject: [PATCH 3/5] update --- dist/index.js | 15 +++++++++------ src/index.ts | 23 +++++++++++------------ 2 files changed, 20 insertions(+), 18 deletions(-) diff --git a/dist/index.js b/dist/index.js index fb64956..f94dd4b 100644 --- a/dist/index.js +++ b/dist/index.js @@ -33273,11 +33273,15 @@ function GetOwnersWithModifiedFiles(codeowners, modifiedFiles, regex_files, owne } async function run() { //# Part 1: Getting all code owners based on their modified files + const pull_request = context.payload.pull_request; + if (!pull_request) { + return; + } try { const workspace_file = `${process.env.GITHUB_WORKSPACE}${getInput('file')}`; //${{ github.workspace }} const core_owner = context.repo.owner; //${{ github.repository_owner }} const core_repo = context.repo.repo; //${{ github.repository }} - const pull_number = context.payload.pull_request?.number; //${{ github.event.pull_request.number }} + const pull_number = pull_request.number; //${{ github.event.pull_request.number }} if (!pull_number) { setFailed('No pull request payload found'); return; @@ -33312,7 +33316,7 @@ async function run() { trimmed_owners.push(owner.replace('@', '')); } //Remove PR author from the user list - const index = trimmed_owners.indexOf(context.payload.pull_request?.user.login); + const index = trimmed_owners.indexOf(pull_request.user.login); if (index >= 0) { trimmed_owners.splice(index, 1); } @@ -33341,11 +33345,10 @@ async function run() { return; } //Remove review requests from users no longer impacted - const currentlyRequested = (response.data.requested_reviewers ?? []).map(r => r.login); - const allCodeowners = Array.from(codeowners.keys()).map(o => o.replace('@', '')); - const toRemove = currentlyRequested.filter(r => !trimmed_owners.includes(r) && allCodeowners.includes(r)); + const currentlyRequested = (pull_request.requested_reviewers ?? []).map((r) => r.login); + const toRemove = currentlyRequested.filter(r => !trimmed_owners.includes(r) && codeowners.has('@' + r)); if (toRemove.length) { - info(`Removing review requests from: ${toRemove.join(', ')}`); + info(`Removing review requests from: ${toRemove.join(' ')}`); await octokit.rest.pulls.removeRequestedReviewers({ owner: core_owner, repo: core_repo, diff --git a/src/index.ts b/src/index.ts index 05275c8..d2607cd 100644 --- a/src/index.ts +++ b/src/index.ts @@ -97,11 +97,16 @@ function GetOwnersWithModifiedFiles( async function run(): Promise { //# Part 1: Getting all code owners based on their modified files + const pull_request = context.payload.pull_request + if (!pull_request) { + return + } + try { const workspace_file = `${process.env.GITHUB_WORKSPACE}${getInput('file')}` //${{ github.workspace }} const core_owner: string = context.repo.owner //${{ github.repository_owner }} const core_repo: string = context.repo.repo //${{ github.repository }} - const pull_number = context.payload.pull_request?.number //${{ github.event.pull_request.number }} + const pull_number = pull_request.number //${{ github.event.pull_request.number }} if (!pull_number) { setFailed('No pull request payload found') return @@ -161,9 +166,7 @@ async function run(): Promise { } //Remove PR author from the user list - const index = trimmed_owners.indexOf( - context.payload.pull_request?.user.login - ) + const index = trimmed_owners.indexOf(pull_request.user.login) if (index >= 0) { trimmed_owners.splice(index, 1) } @@ -198,17 +201,13 @@ async function run(): Promise { //Remove review requests from users no longer impacted const currentlyRequested: string[] = ( - response.data.requested_reviewers ?? [] - ).map(r => r.login) - const allCodeowners = Array.from(codeowners.keys()).map(o => - o.replace('@', '') - ) + pull_request.requested_reviewers ?? [] + ).map((r: {login: string}) => r.login) const toRemove = currentlyRequested.filter( - r => !trimmed_owners.includes(r) && allCodeowners.includes(r) + r => !trimmed_owners.includes(r) && codeowners.has('@' + r) ) - if (toRemove.length) { - info(`Removing review requests from: ${toRemove.join(', ')}`) + info(`Removing review requests from: ${toRemove.join(' ')}`) await octokit.rest.pulls.removeRequestedReviewers({ owner: core_owner, repo: core_repo, From 44fa2cff81d1c2848ee3e7c34e6dc73c9e8246e9 Mon Sep 17 00:00:00 2001 From: SyncIt21 <110812394+SyncIt21@users.noreply.github.com> Date: Tue, 7 Jul 2026 12:06:21 +0530 Subject: [PATCH 4/5] more patches --- dist/index.js | 18 +++++++++--------- src/index.ts | 30 +++++++++++++++--------------- 2 files changed, 24 insertions(+), 24 deletions(-) diff --git a/dist/index.js b/dist/index.js index f94dd4b..1ea1630 100644 --- a/dist/index.js +++ b/dist/index.js @@ -33302,10 +33302,10 @@ async function run() { // Push results per page onto the final array const ownerPathRegexMap = new Map(); const ownersWithModifiedFiles = new Set(); - for await (const page_set of modifiedFilesIterator) { - for (const page of page_set.data) { - GetOwnersWithModifiedFiles(codeowners, page.map(modified_file => modified_file.filename), ownerPathRegexMap, ownersWithModifiedFiles); - } + for await (const page of modifiedFilesIterator) { + GetOwnersWithModifiedFiles(codeowners, page.data + .flatMap(files => files) + .map(modified_file => modified_file.filename), ownerPathRegexMap, ownersWithModifiedFiles); } // Display all code owners info(`Owners With Modified Files: ${ownersWithModifiedFiles.values().toArray().join(' ')}`); @@ -33339,11 +33339,6 @@ async function run() { trimmed_owners.splice(trimmed_owners.indexOf(user), 1); } } - //No reviewers so stop here - if (!trimmed_owners.length) { - info('No reviewers to call'); - return; - } //Remove review requests from users no longer impacted const currentlyRequested = (pull_request.requested_reviewers ?? []).map((r) => r.login); const toRemove = currentlyRequested.filter(r => !trimmed_owners.includes(r) && codeowners.has('@' + r)); @@ -33356,6 +33351,11 @@ async function run() { reviewers: toRemove }); } + //No reviewers so stop here + if (!trimmed_owners.length) { + info('No reviewers to call'); + return; + } //Finally notify all users for review await octokit.rest.pulls.requestReviewers({ owner: core_owner, diff --git a/src/index.ts b/src/index.ts index d2607cd..a587fe3 100644 --- a/src/index.ts +++ b/src/index.ts @@ -141,15 +141,15 @@ async function run(): Promise { // Push results per page onto the final array const ownerPathRegexMap: Map = new Map() const ownersWithModifiedFiles: Set = new Set() - for await (const page_set of modifiedFilesIterator) { - for (const page of page_set.data) { - GetOwnersWithModifiedFiles( - codeowners, - page.map(modified_file => modified_file.filename), - ownerPathRegexMap, - ownersWithModifiedFiles - ) - } + for await (const page of modifiedFilesIterator) { + GetOwnersWithModifiedFiles( + codeowners, + page.data + .flatMap(files => files) + .map(modified_file => modified_file.filename), + ownerPathRegexMap, + ownersWithModifiedFiles + ) } // Display all code owners @@ -193,12 +193,6 @@ async function run(): Promise { } } - //No reviewers so stop here - if (!trimmed_owners.length) { - info('No reviewers to call') - return - } - //Remove review requests from users no longer impacted const currentlyRequested: string[] = ( pull_request.requested_reviewers ?? [] @@ -216,6 +210,12 @@ async function run(): Promise { }) } + //No reviewers so stop here + if (!trimmed_owners.length) { + info('No reviewers to call') + return + } + //Finally notify all users for review await octokit.rest.pulls.requestReviewers({ owner: core_owner, From 5f9dc608fefca83d5460cf7456ffd70eb561cf83 Mon Sep 17 00:00:00 2001 From: SyncIt21 <110812394+SyncIt21@users.noreply.github.com> Date: Tue, 7 Jul 2026 12:09:57 +0530 Subject: [PATCH 5/5] remove --- dist/index.js | 5 ----- src/index.ts | 6 ------ 2 files changed, 11 deletions(-) diff --git a/dist/index.js b/dist/index.js index 1ea1630..347ac06 100644 --- a/dist/index.js +++ b/dist/index.js @@ -33320,11 +33320,6 @@ async function run() { if (index >= 0) { trimmed_owners.splice(index, 1); } - //No reviewers so stop here - if (!trimmed_owners.length) { - info('No reviewers to call'); - return; - } //Remove Invalid users for (const user of trimmed_owners.toReversed()) { try { diff --git a/src/index.ts b/src/index.ts index a587fe3..384a9c2 100644 --- a/src/index.ts +++ b/src/index.ts @@ -171,12 +171,6 @@ async function run(): Promise { trimmed_owners.splice(index, 1) } - //No reviewers so stop here - if (!trimmed_owners.length) { - info('No reviewers to call') - return - } - //Remove Invalid users for (const user of trimmed_owners.toReversed()) { try {