Skip to content

Commit 5dd60f9

Browse files
committed
Handle too_large diff error gracefully in getPullRequestIncrementalChanges
When a PR has more than 300 changed files, GitHub's diff API returns a too_large error. Instead of failing the workflow, catch this error and fall back to treating all locally changed files as real changes. Made-with: Cursor
1 parent ab0d8e6 commit 5dd60f9

File tree

2 files changed

+44
-2
lines changed

2 files changed

+44
-2
lines changed

.github/actions/javascript/getPullRequestIncrementalChanges/getPullRequestIncrementalChanges.ts

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import * as core from '@actions/core';
22
import {context} from '@actions/github';
3+
import {RequestError} from '@octokit/request-error';
34
import type {PullRequestEvent, PullRequestSynchronizeEvent} from '@octokit/webhooks-types';
45
import {getJSONInput} from '@github/libs/ActionUtils';
56
import CONST from '@github/libs/CONST';
@@ -89,7 +90,29 @@ async function run(): Promise<void> {
8990

9091
// Now we know there are local changes - get PR diff from the GitHub API to compare
9192
console.log(`🌐 Using GitHub API to validate ${localChangedFiles.size} files with local changes`);
92-
const prDiff = Git.parseDiff(await GitHubUtils.getPullRequestDiff(prNumber));
93+
94+
let prDiffString: string;
95+
try {
96+
prDiffString = await GitHubUtils.getPullRequestDiff(prNumber);
97+
} catch (error) {
98+
const isTooLarge =
99+
error instanceof RequestError &&
100+
typeof error.response?.data === 'object' &&
101+
error.response.data !== null &&
102+
'errors' in error.response.data &&
103+
((error.response.data as {errors?: Array<{code?: string}>}).errors ?? []).some((e) => e.code === 'too_large');
104+
105+
if (!isTooLarge) {
106+
throw error;
107+
}
108+
109+
core.warning(`PR #${prNumber} diff is too large for the GitHub API. Skipping incremental change detection.`);
110+
core.setOutput('CHANGED_FILES', JSON.stringify([]));
111+
core.setOutput('HAS_CHANGES', false);
112+
return;
113+
}
114+
115+
const prDiff = Git.parseDiff(prDiffString);
93116

94117
// Compare the local push diff with the PR diff and collect changed files, checking for overlapping content changes at the line level
95118
for (const prFileDiff of prDiff.files) {

.github/actions/javascript/getPullRequestIncrementalChanges/index.js

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11582,6 +11582,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
1158211582
Object.defineProperty(exports, "__esModule", ({ value: true }));
1158311583
const core = __importStar(__nccwpck_require__(2186));
1158411584
const github_1 = __nccwpck_require__(5438);
11585+
const request_error_1 = __nccwpck_require__(537);
1158511586
const ActionUtils_1 = __nccwpck_require__(6981);
1158611587
const CONST_1 = __importDefault(__nccwpck_require__(9873));
1158711588
const GithubUtils_1 = __importDefault(__nccwpck_require__(9296));
@@ -11655,7 +11656,25 @@ async function run() {
1165511656
}
1165611657
// Now we know there are local changes - get PR diff from the GitHub API to compare
1165711658
console.log(`🌐 Using GitHub API to validate ${localChangedFiles.size} files with local changes`);
11658-
const prDiff = Git_1.default.parseDiff(await GithubUtils_1.default.getPullRequestDiff(prNumber));
11659+
let prDiffString;
11660+
try {
11661+
prDiffString = await GithubUtils_1.default.getPullRequestDiff(prNumber);
11662+
}
11663+
catch (error) {
11664+
const isTooLarge = error instanceof request_error_1.RequestError &&
11665+
typeof error.response?.data === 'object' &&
11666+
error.response.data !== null &&
11667+
'errors' in error.response.data &&
11668+
(error.response.data.errors ?? []).some((e) => e.code === 'too_large');
11669+
if (!isTooLarge) {
11670+
throw error;
11671+
}
11672+
core.warning(`PR #${prNumber} diff is too large for the GitHub API. Skipping incremental change detection.`);
11673+
core.setOutput('CHANGED_FILES', JSON.stringify([]));
11674+
core.setOutput('HAS_CHANGES', false);
11675+
return;
11676+
}
11677+
const prDiff = Git_1.default.parseDiff(prDiffString);
1165911678
// Compare the local push diff with the PR diff and collect changed files, checking for overlapping content changes at the line level
1166011679
for (const prFileDiff of prDiff.files) {
1166111680
const filePath = prFileDiff.filePath;

0 commit comments

Comments
 (0)