From 63d1f4f8a22a2a3f57e2bcdc94e4b61a02884c27 Mon Sep 17 00:00:00 2001 From: Chuan-kai Lin Date: Mon, 13 Jan 2025 08:03:34 -0800 Subject: [PATCH] getPullRequestEditedDiffRanges: check the number of changed files --- src/analyze.ts | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/analyze.ts b/src/analyze.ts index 488a9ad05..9563bf976 100644 --- a/src/analyze.ts +++ b/src/analyze.ts @@ -298,6 +298,17 @@ async function getPullRequestEditedDiffRanges( if (fileDiffs === undefined) { return undefined; } + if (fileDiffs.length >= 300) { + // The "compare two commits" API returns a maximum of 300 changed files. If + // we see that many changed files, it is possible that there could be more, + // with the rest being truncated. In this case, we should not attempt to + // compute the diff ranges, as the result would be incomplete. + logger.warning( + `Cannot retrieve the full diff because there are too many ` + + `(${fileDiffs.length}) changed files in the pull request.`, + ); + return undefined; + } const results: DiffThunkRange[] = []; for (const filediff of fileDiffs) { const diffRanges = getDiffRanges(filediff, logger);