Skip to content

Commit 392edc8

Browse files
theoryshawclaude
andcommitted
fix: paginate on the API page size, not on how many PRs survive curation
Second run got as far as fetching PRs and reported: Found 0 open pull requests (curation selects 160) ⚠️ 160 selected PR(s) are no longer open and will be skipped All 160 are open. The walk over /pulls decided it had reached the last page by testing `len(prs) < 100` *after* filtering. A page of 100 open PRs almost never contains 100 that a curator selected, so the loop stopped on page 1 — and since the API returns newest first while this profile's PRs are older, page 1 held none of them. Zero. Pagination now tests the count the API returned; filtering happens after and cannot end the walk. Simulated against the real shape (20 selected PRs spread across 80 pages): 0 found before, 20 after. The bug was latent in the original code, which filtered by USERNAMES before the same check — it only ever ran with USERNAMES empty, so nothing was filtered and the count was the raw page size. Making curation unconditional is what exposed it. Also fixes the crash that followed. The "no open PRs" path prints "creating branch with just main branch updates" and then pushes that branch, but nothing creates it — apply_prs_to_branch() normally does, and that path skips it. The push failed with "src refspec build-... does not match any", which says nothing about the actual problem. It now creates the branch, so an empty curation produces an empty build and a report rather than a misleading git error. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
1 parent 9edef08 commit 392edc8

1 file changed

Lines changed: 25 additions & 8 deletions

File tree

automation/scripts/00_clone_merge_and_create_branch.py

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -338,23 +338,28 @@ def get_open_prs():
338338
print(f"Error fetching PRs: {response.status_code}")
339339
break
340340

341-
prs = response.json()
342-
if not prs:
341+
page_items = response.json()
342+
if not page_items:
343343
break
344344

345+
# Pagination is decided by how many items the API returned, NOT by how
346+
# many survive curation. Testing the filtered count ends the walk on the
347+
# first page for any selective profile — a page of 100 open PRs rarely
348+
# contains 100 that a curator selected — and silently yields a fraction
349+
# of the curation, or nothing at all.
350+
is_last_page = len(page_items) < params["per_page"]
351+
345352
# Apply the active curation. For the legacy/`everything` case this is
346353
# exactly the old author filter; for an `allowlist` profile it is also
347354
# what narrows 847 open PRs down to the ones the curator chose.
348-
prs = [
355+
all_prs.extend(
349356
pr
350-
for pr in prs
357+
for pr in page_items
351358
if CURATION.selects(pr["number"], (pr.get("user") or {}).get("login"))
352-
]
353-
354-
all_prs.extend(prs)
359+
)
355360
page += 1
356361

357-
if len(prs) < 100: # Last page
362+
if is_last_page:
358363
break
359364

360365
if CURATION.mode == bonsaipr_profile.MODE_ALLOWLIST:
@@ -1489,6 +1494,18 @@ def main():
14891494
applied, failed, skipped = [], [], []
14901495
failed_pr_test_results = {}
14911496
pr_conflict_data = {}
1497+
# Actually create the branch before pushing it. apply_prs_to_branch()
1498+
# normally does this, but it is skipped entirely on this path, so the
1499+
# push below used to fail with "src refspec does not match any" — an
1500+
# error that says nothing about the real problem, which is that the
1501+
# curation matched no open PRs.
1502+
original_dir = os.getcwd()
1503+
try:
1504+
os.chdir(work_dir)
1505+
subprocess.run(["git", "branch", "-D", branch_name], capture_output=True)
1506+
subprocess.run(["git", "checkout", "-b", branch_name], check=True)
1507+
finally:
1508+
os.chdir(original_dir)
14921509
# Push branch to fork (even if empty)
14931510
push_branch_to_fork(branch_name)
14941511
# Print current branch for verification

0 commit comments

Comments
 (0)