Skip to content

fix(scripts): correct premature return in markStale and add --debug flag to auto-close-duplicates#65344

Open
FrancescoCastaldi wants to merge 2 commits into
anthropics:mainfrom
FrancescoCastaldi:fix/sweep-markstale-premature-return
Open

fix(scripts): correct premature return in markStale and add --debug flag to auto-close-duplicates#65344
FrancescoCastaldi wants to merge 2 commits into
anthropics:mainfrom
FrancescoCastaldi:fix/sweep-markstale-premature-return

Conversation

@FrancescoCastaldi

Copy link
Copy Markdown

Summary

This PR fixes a logic bug in scripts/sweep.ts and improves the logging ergonomics of scripts/auto-close-duplicates.ts.


scripts/sweep.ts — fix premature return in markStale()

Bug: When iterating over paginated issues (sorted by updated_at asc), the original code used return labeled as soon as it encountered an issue newer than the stale cutoff. This exits the entire function, meaning issues on subsequent pages are never evaluated even if they were correctly stale.

Fix: Replace return labeled with break. Since issues are sorted ascending by updated_at, a break exits the inner issue-loop for the current page; the outer page-loop then naturally terminates on the next iteration because all further pages will also be newer than the cutoff. This ensures every page is processed correctly.


scripts/auto-close-duplicates.ts — add --debug flag to control verbosity

Problem: All [DEBUG] log lines were printed unconditionally on every CI run, producing hundreds of noisy lines even in normal operation.

Fix: Introduces a small log(level, message) helper and a --debug CLI flag:

  • DEBUG messages are suppressed unless --debug is passed
  • INFO, SUCCESS, and ERROR messages always print
  • Also adds argv: string[] to the declare global block so TypeScript resolves process.argv without a cast

Usage:

# Normal run (quiet)
bun run scripts/auto-close-duplicates.ts

# Verbose run (all debug output)
bun run scripts/auto-close-duplicates.ts --debug

In markStale(), when an issue's updated_at is newer than the cutoff
the original code used `return labeled` which exits the entire function,
skipping all remaining pages. Since issues are sorted by updated asc,
a `break` is correct: it exits the inner for-loop over issues on the
current page and lets the outer page-loop also break naturally (because
subsequent pages will have even newer issues). This ensures all stale
issues across pages are consistently processed.
…logs

Refactor logging to use a dedicated log function and update debug messages.All [DEBUG] console.log calls were printed unconditionally, flooding
CI output on every run. This refactor introduces a structured log()
helper and a --debug CLI flag: DEBUG-level messages are suppressed
unless the flag is passed, while INFO/SUCCESS/ERROR always print.
Also adds argv to the global process declaration so TypeScript
no longer needs a cast to access process.argv.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants