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:
@@ -108,6 +108,43 @@ Changed Files: 2 files`,
|
||||
);
|
||||
});
|
||||
|
||||
test("renders an unknown file count when GraphQL returns null files (very large PR)", () => {
|
||||
// GitHub declines to compute the diff for very large PRs and returns
|
||||
// `files: null`. `changedFiles` is misreported as 0 in that case, so the
|
||||
// count must render as unavailable rather than "0 files".
|
||||
const prData: GitHubPullRequest = {
|
||||
title: "Very large PR",
|
||||
body: "PR body",
|
||||
author: { login: "test-user" },
|
||||
baseRefName: "main",
|
||||
headRefName: "feature/test",
|
||||
headRefOid: "abc123",
|
||||
isCrossRepository: false,
|
||||
headRepository: { owner: { login: "testowner" }, name: "testrepo" },
|
||||
createdAt: "2023-01-01T00:00:00Z",
|
||||
additions: 50,
|
||||
deletions: 30,
|
||||
state: "OPEN",
|
||||
labels: {
|
||||
nodes: [],
|
||||
},
|
||||
commits: {
|
||||
totalCount: 3,
|
||||
nodes: [],
|
||||
},
|
||||
files: null,
|
||||
comments: {
|
||||
nodes: [],
|
||||
},
|
||||
reviews: {
|
||||
nodes: [],
|
||||
},
|
||||
};
|
||||
|
||||
const result = formatContext(prData, true);
|
||||
expect(result).toContain("Changed Files: unknown (file list unavailable)");
|
||||
});
|
||||
|
||||
test("formats Issue context correctly", () => {
|
||||
const issueData: GitHubIssue = {
|
||||
title: "Test Issue",
|
||||
|
||||
Reference in New Issue
Block a user