mirror of
https://github.com/anthropics/claude-code-action.git
synced 2026-08-22 03:18:54 +08:00
fix: handle null files field from GraphQL on very large PRs (#1593)
GitHub's GraphQL API returns files: null (with no errors entry, and changedFiles misreported as 0) when a PR's diff is too large to compute. The unguarded pullRequest.files.nodes dereference in the fetcher crashed the action with 'TypeError: null is not an object', and the formatter had the same latent crash on prData.files.nodes.length. Widen the GitHubPullRequest type to files | null so the compiler enforces guards, degrade gracefully in the fetcher with a warning, and render the file count as unavailable (not '0 files') in the formatter. Fixes #1587
This commit is contained in:
@@ -424,7 +424,12 @@ export async function fetchGitHubData({
|
||||
if (prResult.repository.pullRequest) {
|
||||
const pullRequest = prResult.repository.pullRequest;
|
||||
contextData = pullRequest;
|
||||
changedFiles = pullRequest.files.nodes || [];
|
||||
if (pullRequest.files === null) {
|
||||
console.warn(
|
||||
`GitHub did not return the file list for PR #${prNumber} (diff likely too large); proceeding without file-level context`,
|
||||
);
|
||||
}
|
||||
changedFiles = pullRequest.files?.nodes ?? [];
|
||||
comments = filterCommentsByActor(
|
||||
filterCommentsToTriggerTime(
|
||||
pullRequest.comments?.nodes || [],
|
||||
|
||||
@@ -28,7 +28,7 @@ PR Labels: ${formatLabels(prData.labels.nodes)}
|
||||
PR Additions: ${prData.additions}
|
||||
PR Deletions: ${prData.deletions}
|
||||
Total Commits: ${prData.commits.totalCount}
|
||||
Changed Files: ${prData.files.nodes.length} files`;
|
||||
Changed Files: ${prData.files ? `${prData.files.nodes.length} files` : "unknown (file list unavailable)"}`;
|
||||
} else {
|
||||
const issueData = contextData as GitHubIssue;
|
||||
const sanitizedTitle = sanitizeContent(issueData.title);
|
||||
|
||||
+5
-1
@@ -85,9 +85,13 @@ export type GitHubPullRequest = {
|
||||
commit: GitHubCommit;
|
||||
}>;
|
||||
};
|
||||
// GitHub's GraphQL `files` field resolves to null when the PR's diff is too
|
||||
// large for GitHub to compute (very large PRs). `changedFiles` is also
|
||||
// misreported as 0 in that case, so the null must be guarded and treated as
|
||||
// "file list unavailable" rather than "no files changed".
|
||||
files: {
|
||||
nodes: GitHubFile[];
|
||||
};
|
||||
} | null;
|
||||
comments: {
|
||||
nodes: GitHubComment[];
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user