Repository navigation
fix: stop Gitea changed-files pagination at the advertised total - #4306
Conversation
get_change_file_pull_request only ended at an empty page, so it always requested one page past the last. Forgejo answers that page with HTTP 200 and a literal `null`, which the changed-files validation rejects, and /review stopped on a complete 15-file list. Read X-Total-Count from the response headers (case-insensitive, plain dict or urllib3 HTTPHeaderDict) and end the walk once that many files are collected. A count that differs from the advertised total, a `null` or malformed page before it is reached, and malformed entries still raise. Responses without a usable X-Total-Count keep the empty-page ending. Fixes The-PR-Agent#4305
PR Reviewer Guide 🔍Here are some key observations to aid the review process:
⚙️ Agent run details
|
PR Code Suggestions ✨Explore these optional code suggestions:
⚙️ Agent run details
|
IsmaelMartinez
left a comment
There was a problem hiding this comment.
Thanks for picking up #4305 so quickly, approving and merging.
User description
Summary
RepoApi.get_change_file_pull_request()only stopped at an empty page, so it always asked for one page past the last. Forgejo answers that extra page with HTTP 200 and a literalnull. The changed-files validation from #3857 rejectsnull, so/reviewfailed on a complete file list.The loop now reads
X-Total-Countfrom the response headers and stops once that many files have been collected. The lookup ignores header case and works with both a plain dict and urllib3'sHTTPHeaderDict, which is what giteapy returns with_preload_content=False.The #3857 protection still holds:
nullor malformed page that arrives before the advertised total is reached, and a malformed entry all still raise.X-Total-Countnow raises too, whether the walk ends at the total or at an empty page.X-Total-Count(missing, non-numeric or negative) keep the old empty-page ending.Fixes #4305
Behavior change
A server that advertises more files than it delivers, or fewer, now stops the review. Before this change it returned the partial list without any error. The issue asks for this ("a count that does not match the advertised total should still stop the review"). The empty-page half of the check is the
or not page_itemsclause, so it is easy to drop if you'd rather not have it.Tests
All tests are mock-only and added to
tests/unittest/test_gitea_provider.py. I have not checked against a real plain Gitea server that this endpoint returnsX-Total-Count; the tests use mocks and the Forgejo reproduction from the issue.nullpage now returns the 15 files with onecall_apicall. This is run against a plain dict, lowercase header names and anHTTPHeaderDict.nullnext page, an empty next page, or more files than advertised all raise.X-Total-Countfalls back to the empty-page ending.mainValueError: Invalid Gitea changed-files pageandDID NOT RAISEfor the two mismatch cases.tests/unittest/test_gitea_*.pytests/unittestruff checkon the changed files reports "All checks passed!", andpre-commit run --filespasses on the changed files (with theruff-checkhook skipped, sinceruff checkwas run directly).Sibling code paths
The other paginated helper in the same provider is
_list_all_pages(gitea_provider.py~1187-1219), which is used for PR commits and review comments. It does not raise onnull; it treatsnullas the end of the list. So it doesn't hit this failure, but it also always makes one trailing request, and anullpage in the middle of a walk would cut the list short without an error. That is a different code path, so I left it out of this PR. I'm happy to follow up if you want the same header-based stop there.No other git provider shares this loop.
I used an AI coding assistant for this change, then reviewed the diff and re-ran the tests myself.
PR Type
Bug fix, Tests
Description
Stop Gitea pagination at advertised file totals.
Reject mismatched counts and malformed file entries.
Preserve fallback pagination for unusable total headers.
Add mocked Forgejo pagination regression tests.
Diagram Walkthrough
File Walkthrough
gitea_provider.py
Honor advertised totals during changed-files paginationpr_agent/git_providers/gitea_provider.py
_advertised_total()to parse nonnegativeX-Total-Countvaluescase-insensitively.
the advertised total.
total.
unusable.
test_gitea_provider.py
Cover advertised totals and pagination validation regressionstests/unittest/test_gitea_provider.py
nullresponse and verify no extra requestoccurs.
HTTPHeaderDict.⚙️ Agent run details