@@ -286,6 +286,48 @@ def parse_args() -> argparse.Namespace:
286286 return parser .parse_args ()
287287
288288
289+ def process_repo (
290+ repo : RepoSpec ,
291+ * ,
292+ qpk_sha : str ,
293+ close_superseded : bool ,
294+ env : dict [str , str ],
295+ ) -> None :
296+ """Queue the current pin when eligible, then retire verified older pins.
297+
298+ A current generated PR may already have merged by the time the hourly
299+ workflow runs again. Cleanup must therefore be independent of finding an
300+ open current PR; otherwise historical proposal branches accumulate forever.
301+ """
302+
303+ branch = expected_branch (repo , qpk_sha )
304+ pr = open_pr_payload (repo , branch , env = env )
305+ if pr is None :
306+ print (f"{ repo .name } : no current generated PR" )
307+ else :
308+ reason = candidate_reason (
309+ pr = pr ,
310+ changed_files = changed_files (repo , int (pr ["number" ]), env = env ),
311+ pyproject_text = pyproject_text (repo , pr ["headRefOid" ], env = env ),
312+ qpk_sha = qpk_sha ,
313+ )
314+ if reason is not None :
315+ print (f"{ repo .name } : skipped:{ reason } " )
316+ else :
317+ merge_candidate (repo , pr , env = env )
318+ print (f"{ repo .name } : queued:{ pr ['url' ]} " )
319+
320+ if close_superseded :
321+ closed = close_superseded_candidates (
322+ repo ,
323+ current_branch = branch ,
324+ qpk_sha = qpk_sha ,
325+ env = env ,
326+ )
327+ if closed :
328+ print (f"{ repo .name } : closed_superseded:{ ',' .join (closed )} " )
329+
330+
289331def main () -> int :
290332 args = parse_args ()
291333 qpk_sha = args .qpk_sha .strip ()
@@ -299,31 +341,12 @@ def main() -> int:
299341 failures = 0
300342 for repo in STRATEGY_REPOS :
301343 try :
302- branch = expected_branch (repo , qpk_sha )
303- pr = open_pr_payload (repo , branch , env = env )
304- if pr is None :
305- print (f"{ repo .name } : no current generated PR" )
306- continue
307- reason = candidate_reason (
308- pr = pr ,
309- changed_files = changed_files (repo , int (pr ["number" ]), env = env ),
310- pyproject_text = pyproject_text (repo , pr ["headRefOid" ], env = env ),
344+ process_repo (
345+ repo ,
311346 qpk_sha = qpk_sha ,
347+ close_superseded = args .close_superseded ,
348+ env = env ,
312349 )
313- if reason is not None :
314- print (f"{ repo .name } : skipped:{ reason } " )
315- continue
316- merge_candidate (repo , pr , env = env )
317- print (f"{ repo .name } : queued:{ pr ['url' ]} " )
318- if args .close_superseded :
319- closed = close_superseded_candidates (
320- repo ,
321- current_branch = branch ,
322- qpk_sha = qpk_sha ,
323- env = env ,
324- )
325- if closed :
326- print (f"{ repo .name } : closed_superseded:{ ',' .join (closed )} " )
327350 except (RuntimeError , subprocess .CalledProcessError , ValueError , UnicodeDecodeError ) as exc :
328351 failures += 1
329352 if isinstance (exc , subprocess .CalledProcessError ):
0 commit comments