From 15e2d93989ca5a03b980ce673e2b02aee9f3a5d6 Mon Sep 17 00:00:00 2001 From: Molecule AI Core-DevOps Date: Mon, 11 May 2026 05:45:12 +0000 Subject: [PATCH] fix(gate-check-v3): add pagination to api_list for comment/review scans 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 --- tools/gate-check-v3/gate_check.py | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/tools/gate-check-v3/gate_check.py b/tools/gate-check-v3/gate_check.py index 72bfcf28..77c106da 100644 --- a/tools/gate-check-v3/gate_check.py +++ b/tools/gate-check-v3/gate_check.py @@ -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):