Skip to content

Commit 7fd08d4

Browse files
jainakshay93claude
andauthored
fix: reconstruct diff from per-file patches when GitHub 406s on large PRs (#61)
_fetch_pr_once fetches the diff via the .diff media type, which GitHub 406s when the diff is too large (e.g. 722-file PR), aborting the review. On 406, rebuild the unified diff from the per-file patches already fetched from the /files API. Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent 3c8eca9 commit 7fd08d4

1 file changed

Lines changed: 21 additions & 6 deletions

File tree

src/pr_af/github/client.py

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -204,11 +204,26 @@ async def _fetch_pr_once(self, pr_url: str) -> GitHubPRData:
204204
commit_page += 1
205205

206206
diff_headers = {**auth_headers, "Accept": "application/vnd.github.v3.diff"}
207-
diff_resp = await client.get(
208-
f"{self.base_url}/repos/{owner}/{repo}/pulls/{number}",
209-
headers=diff_headers,
210-
)
211-
diff_resp.raise_for_status()
207+
try:
208+
diff_resp = await client.get(
209+
f"{self.base_url}/repos/{owner}/{repo}/pulls/{number}",
210+
headers=diff_headers,
211+
)
212+
diff_resp.raise_for_status()
213+
full_diff = diff_resp.text
214+
except httpx.HTTPStatusError as exc:
215+
# GitHub returns 406 for the one-shot .diff media type when a
216+
# PR's diff is too large to generate (very large PRs). The
217+
# per-file patches were already fetched from the /files API
218+
# above, so reconstruct an equivalent unified diff from them
219+
# instead of failing the whole review.
220+
if exc.response.status_code != 406:
221+
raise
222+
full_diff = "\n".join(
223+
f"diff --git a/{f.path} b/{f.path}\n--- a/{f.path}\n+++ b/{f.path}\n{f.patch}"
224+
for f in changed_files
225+
if f.patch
226+
)
212227

213228
return GitHubPRData(
214229
owner=owner,
@@ -221,7 +236,7 @@ async def _fetch_pr_once(self, pr_url: str) -> GitHubPRData:
221236
base_sha=pr_data.get("base", {}).get("sha", ""),
222237
head_sha=pr_data.get("head", {}).get("sha", ""),
223238
commit_messages=commit_messages,
224-
diff=diff_resp.text,
239+
diff=full_diff,
225240
changed_files=changed_files,
226241
)
227242

0 commit comments

Comments
 (0)