fix(gate-check-v3): add pagination to api_list for comment/review scans
All checks were successful
Secret scan / Scan diff for credential-shaped strings (pull_request) Successful in 7s
sop-tier-check / tier-check (pull_request) Successful in 8s

Paginate all list endpoints (comments, reviews) to handle PRs with
many comments without missing entries. Uses per_page=100 with page
increment loop, safety-capped at 20 pages.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
Molecule AI · core-devops 2026-05-11 05:45:12 +00:00
parent 4ac93975f3
commit 53d801d19a

View File

@ -53,12 +53,28 @@ def api_get(path: str) -> dict | list:
raise GiteaError(f"GET {url}{e.code}: {body[:300]}")
def api_list(path: str) -> list:
"""Paginate a list endpoint."""
result = api_get(path)
if isinstance(result, list):
return result
return result.get("data", result.get("items", []))
def api_list(path: str, per_page: int = 100) -> list:
"""Paginate a list endpoint using Link headers (Gitea/GitHub convention)."""
results = []
page = 1
while True:
paged_path = f"{path}?per_page={per_page}&page={page}"
result = api_get(paged_path)
if isinstance(result, list):
results.extend(result)
if len(result) < per_page:
break
page += 1
else:
# Some endpoints return an object with a data/items key
data = result.get("data", result.get("items", result))
if isinstance(data, list):
results.extend(data)
break
# Safety cap to avoid runaway pagination
if page > 20:
break
return results
class GiteaError(Exception):