Repository: DefinitelyTyped/dt-mergebot (ts)

Issue:
Fails to comment on huge PRs
TL;DR: when opening huge PRs, such as https://github.com/DefinitelyTyped/DefinitelyTyped/pull/62106 - mergebot never picks it up.

> Someone would need to [log into the azure functions](https://github.com/DefinitelyTyped/dt-mergebot/#meta ) to read the logs to know exactly why, but there is a 'too big to review' style check in the bot which this doesn't seem to be getting hit with.
> _Originally posted by @orta in https://github.com/DefinitelyTyped/DefinitelyTyped/issues/62106#issuecomment-1242663828_

Other huge PRs that it didn't pick up:
- https://github.com/DefinitelyTyped/DefinitelyTyped/pull/61722
- https://github.com/DefinitelyTyped/DefinitelyTyped/pull/62194
- https://github.com/DefinitelyTyped/DefinitelyTyped/pull/62193
- https://github.com/DefinitelyTyped/DefinitelyTyped/pull/62192

Pull request:
If there are over 500 files changed, don't fetch more than that
This should avoid [the problem seen in this PR](https://github.com/DefinitelyTyped/DefinitelyTyped/pull/62106) ***BUT*** it means that when there are too many files, it should be taken more seriously, since the bot wouldn't go over any of the extra ones.

So I also added a "Too Many Files" label and made it use it (otherwise it would only show an easy-to-miss line at the bottom of the welcome message).

Fixes #447. Probably. Maybe.

Patch:
diff --git a/src/basic.ts b/src/basic.ts
index 53ce1a6..c5ffa7a 100644
--- a/src/basic.ts
+++ b/src/basic.ts
@@ -44,6 +44,7 @@ export const LabelNames = [
     "Too Many Owners",
     "Untested Change",
     "Check Config",
+    "Too Many Files",
     "Huge Change",
     "Needs Actions Permission",
     ...StalenessKinds,
diff --git a/src/compute-pr-actions.ts b/src/compute-pr-actions.ts
index 7f8fb5b..7b191bc 100644
--- a/src/compute-pr-actions.ts
+++ b/src/compute-pr-actions.ts
@@ -252,6 +252,7 @@ export function process(prInfo: BotResult,
     label("Too Many Owners", info.tooManyOwners);
     label("Check Config", info.checkConfig);
     label("Untested Change", info.isUntested);
+    label("Too Many Files", info.tooManyFiles);
     label("Huge Change", info.hugeChange);
     if (info.staleness?.state === "nearly" || info.staleness?.state === "done") label(info.staleness.kind);
 
diff --git a/src/pr-info.ts b/src/pr-info.ts
index fe68c09..5f04af0 100644
--- a/src/pr-info.ts
+++ b/src/pr-info.ts
@@ -7,6 +7,7 @@ import { PR_repository_pullRequest,
 import { getMonthlyDownloadCount } from "./util/npm";
 import { fetchFile as defaultFetchFile } from "./util/fetchFile";
 import { noNullish, someLast, sameUser, authorNotBot, max, abbrOid } from "./util/util";
+import { TOO_MANY_FILES } from "./queries/pr-query";
 import * as comment from "./util/comment";
 import * as urls from "./urls";
 import * as HeaderParser from "@definitelytyped/header-parser";
@@ -209,13 +210,14 @@ export async function deriveStateForPR(
     // that case `files.totalCount` would be 3k so it'd fit the count but `changedFiles` would
     // be correct; so to be safe: check it, and warn if there are many files (or zero)
     const tooManyFiles = !fileCount // should never happen, make it look fishy if it does
-        || fileCount !== prInfo.files?.nodes?.length // didn't get all files somehow
-        || fileCount > 500; // suspiciously many files
+        || fileCount > TOO_MANY_FILES // suspiciously many files
+        || fileCount !== prInfo.files?.nodes?.length; // didn't get all files (probably too many)
     const hugeChange = prInfo.additions + prInfo.deletions > 5000;
 
+    const paths = noNullish(prInfo.files?.nodes).map(f => f.path).sort();
+    if (paths.length > TOO_MANY_FILES) paths.length = TOO_MANY_FILES; // redundant, but just in case
     const pkgInfoEtc = await getPackageInfosEtc(
-        noNullish(prInfo.files?.nodes).map(f => f.path).sort(),
-        prInfo.headRefOid, baseId,
+        paths, prInfo.headRefOid, baseId,
         fetchFile, async name => await getDownloads(name, lastPushDate));
     if (pkgInfoEtc instanceof Error) return botError(pkgInfoEtc.message);
     const { pkgInfo, popularityLevel } = pkgInfoEtc;
diff --git a/src/queries/pr-query.ts b/src/queries/pr-query.ts
index 367239f..36e0eeb 100644
--- a/src/queries/pr-query.ts
+++ b/src/queries/pr-query.ts
@@ -4,6 +4,8 @@ import { PR, PRVariables, PR_repository_pullRequest_files_nodes } from "./schema
 import { PRFiles, PRFilesVariables } from "./schema/PRFiles";
 import { noNullish } from "../util/util";
 
+export const TOO_MANY_FILES = 500;
+
 // Note: If you want to work on this in local a copy of GraphiQL:
 // - Download the electron app: https://github.com/skevy/graphiql-app/releases
 // - Then set the headers:
@@ -185,7 +187,7 @@ export async function getPRInfo(prNumber: number) {
     return info;
 }
 
-export async function getPRInfoFirst(prNumber: number) {
+async function getPRInfoFirst(prNumber: number) {
     // The query can return a mergeable value of `UNKNOWN`, and then it takes a
     // while to get the actual value while GH refreshes the state (verified
     // with GH that this is expected).  So implement a simple retry thing to
@@ -240,7 +242,7 @@ async function getPRInfoRest(prNumber: number, endCursor: string | null,
         const newFiles = result.data.repository?.pullRequest?.files;
         if (!newFiles) return;
         files.push(...noNullish(newFiles.nodes));
-        if (!newFiles.pageInfo.hasNextPage) return;
+        if (files.length >= TOO_MANY_FILES || !newFiles.pageInfo.hasNextPage) return;
         endCursor = newFiles.pageInfo.endCursor;
     }
 }
diff --git a/src/run.ts b/src/run.ts
index 033c321..71b7e5e 100755
--- a/src/run.ts
+++ b/src/run.ts
@@ -63,7 +63,7 @@ const show = (name: string, value: unknown) => {
 
 const start = async function () {
     console.log(`Getting open PRs.`);
-    const { prs: prs, cardIDs } = await getAllOpenPRsAndCardIDs();
+    const { prs, cardIDs } = await getAllOpenPRsAndCardIDs();
     //
     for (const pr of prs) {
         if (!shouldRunOn(pr)) continue;


Test patch:
diff --git a/src/_tests/cachedQueries.json b/src/_tests/cachedQueries.json
index 554da2f..b8a613a 100644
--- a/src/_tests/cachedQueries.json
+++ b/src/_tests/cachedQueries.json
@@ -53,6 +53,11 @@
       "name": "Author is Owner",
       "__typename": "Label"
     },
+    {
+      "id": "LA_kwDOAFz6BM7QXorW",
+      "name": "Blocked upstream",
+      "__typename": "Label"
+    },
     {
       "id": "MDU6TGFiZWwyMTU0ODE2NTQ5",
       "name": "Check Config",
@@ -123,6 +128,11 @@
       "name": "Edits Owners",
       "__typename": "Label"
     },
+    {
+      "id": "LA_kwDOAFz6BM71Jg4R",
+      "name": "github_actions",
+      "__typename": "Label"
+    },
     {
       "id": "MDU6TGFiZWw1ODMyOTQ0NzQ=",
       "name": "Has Merge Conflict",
@@ -258,6 +268,11 @@
       "name": "The CI is blocked",
       "__typename": "Label"
     },
+    {
+      "id": "LA_kwDOAFz6BM8AAAABEGgY4Q",
+      "name": "Too Many Files",
+      "__typename": "Label"
+    },
     {
       "id": "MDU6TGFiZWwyMTU2MzIyMzcx",
       "name": "Too Many Owners",
diff --git a/src/_tests/fixtures/44424-1-travis-instantly-finished/mutations.json b/src/_tests/fixtures/44424-1-travis-instantly-finished/mutations.json
index 9b682b4..134c7ba 100644
--- a/src/_tests/fixtures/44424-1-travis-instantly-finished/mutations.json
+++ b/src/_tests/fixtures/44424-1-travis-instantly-finished/mutations.json
@@ -13,7 +13,8 @@
     "variables": {
       "input": {
         "labelIds": [
-          "MDU6TGFiZWwyOTUzOTk4NzE4"
+          "MDU6TGFiZWwyOTUzOTk4NzE4",
+          "LA_kwDOAFz6BM8AAAABEGgY4Q"
         ],
         "labelableId": "MDExOlB1bGxSZXF1ZXN0NDEyMjY1MDE2"
       }
diff --git a/src/_tests/fixtures/44424-1-travis-instantly-finished/result.json b/src/_tests/fixtures/44424-1-travis-instantly-finished/result.json
index 52638a5..d79f08a 100644
--- a/src/_tests/fixtures/44424-1-travis-instantly-finished/result.json
+++ b/src/_tests/fixtures/44424-1-travis-instantly-finished/result.json
@@ -2,7 +2,8 @@
   "projectColumn": "Needs Maintainer Action",
   "labels": [
     "Possibly Edits Infrastructure",
-    "Author is Owner"
+    "Author is Owner",
+    "Too Many Files"
   ],
   "responseComments": [
     {
diff --git a/src/_tests/fixtures/44424-2-after-travis-second/mutations.json b/src/_tests/fixtures/44424-2-after-travis-second/mutations.json
index 4a63d00..a290c41 100644
--- a/src/_tests/fixtures/44424-2-after-travis-second/mutations.json
+++ b/src/_tests/fixtures/44424-2-after-travis-second/mutations.json
@@ -13,7 +13,8 @@
     "variables": {
       "input": {
         "labelIds": [
-          "MDU6TGFiZWwyOTUzOTk4NzE4"
+          "MDU6TGFiZWwyOTUzOTk4NzE4",
+          "LA_kwDOAFz6BM8AAAABEGgY4Q"
         ],
         "labelableId": "MDExOlB1bGxSZXF1ZXN0NDEyMjY1MDE2"
       }
diff --git a/src/_tests/fixtures/44424-2-after-travis-second/result.json b/src/_tests/fixtures/44424-2-after-travis-second/result.json
index 5e5532a..df3a889 100644
--- a/src/_tests/fixtures/44424-2-after-travis-second/result.json
+++ b/src/_tests/fixtures/44424-2-after-travis-second/result.json
@@ -2,7 +2,8 @@
   "projectColumn": "Waiting for Code Reviews",
   "labels": [
     "Possibly Edits Infrastructure",
-    "Author is Owner"
+    "Author is Owner",
+    "Too Many Files"
   ],
   "responseComments": [
     {