mirror of
https://github.com/BerriAI/litellm.git
synced 2026-10-05 02:41:56 +00:00
fix(triage): apply --limit consistently in dry-run and close modes
Previously --limit was only honored in real-close mode because closed was incremented inside an 'if not dry_run' guard. A dry-run preview with --limit N still iterated and printed every matching PR, defeating the purpose of using --limit to preview a small batch. Count both dry-run and real close actions toward the limit so the flag behaves identically in both modes.
This commit is contained in:
parent
1845b0d940
commit
542dde7990
2 changed files with 56 additions and 6 deletions
16
.github/scripts/close_low_quality_prs.py
vendored
16
.github/scripts/close_low_quality_prs.py
vendored
|
|
@ -392,7 +392,11 @@ def main() -> int:
|
|||
"--limit",
|
||||
type=int,
|
||||
default=None,
|
||||
help="Maximum number of PRs to close in one run (safety net).",
|
||||
help=(
|
||||
"Maximum number of PRs to close in one run (safety net). "
|
||||
"Applied in dry-run too so `--limit N` previews exactly the "
|
||||
"first N closures."
|
||||
),
|
||||
)
|
||||
args = parser.parse_args()
|
||||
|
||||
|
|
@ -446,11 +450,11 @@ def main() -> int:
|
|||
label=args.close_label,
|
||||
)
|
||||
|
||||
if not dry_run:
|
||||
closed += 1
|
||||
if args.limit is not None and closed >= args.limit:
|
||||
print(f"\nReached --limit={args.limit}; stopping.")
|
||||
break
|
||||
closed += 1
|
||||
if args.limit is not None and closed >= args.limit:
|
||||
verb = "Would close" if dry_run else "Closed"
|
||||
print(f"\nReached --limit={args.limit} ({verb} count); stopping.")
|
||||
break
|
||||
|
||||
print("\n=== Summary ===")
|
||||
for key, value in summary.items():
|
||||
|
|
|
|||
|
|
@ -447,6 +447,52 @@ class TestMainOptoutLabelDefault:
|
|||
assert default not in captured["optout_labels"], default
|
||||
|
||||
|
||||
class TestMainLimitFlag:
|
||||
"""`--limit N` must cap closures in both dry-run and real mode."""
|
||||
|
||||
def _patch_three_closeable_prs(self, closer_module, monkeypatch):
|
||||
prs = [
|
||||
{
|
||||
"number": i,
|
||||
"title": f"p{i}",
|
||||
"createdAt": "2026-05-10T00:00:00Z",
|
||||
"isDraft": False,
|
||||
"labels": [],
|
||||
"author": {"login": f"ext{i}"},
|
||||
}
|
||||
for i in (1, 2, 3)
|
||||
]
|
||||
monkeypatch.setattr(closer_module, "fetch_open_prs", lambda repo: prs)
|
||||
monkeypatch.setattr(
|
||||
closer_module,
|
||||
"evaluate_pr",
|
||||
lambda pr, now, mad, ms, repo, ol: ("close", 2, 30),
|
||||
)
|
||||
called: list[int] = []
|
||||
|
||||
def fake_close_pr(pr, **kwargs):
|
||||
called.append(pr["number"])
|
||||
|
||||
monkeypatch.setattr(closer_module, "close_pr", fake_close_pr)
|
||||
return called
|
||||
|
||||
def test_should_stop_at_limit_in_dry_run(self, closer_module, monkeypatch):
|
||||
called = self._patch_three_closeable_prs(closer_module, monkeypatch)
|
||||
monkeypatch.setattr(sys, "argv", ["close_low_quality_prs.py", "--limit", "2"])
|
||||
rc = closer_module.main()
|
||||
assert rc == 0
|
||||
assert len(called) == 2
|
||||
|
||||
def test_should_stop_at_limit_when_closing(self, closer_module, monkeypatch):
|
||||
called = self._patch_three_closeable_prs(closer_module, monkeypatch)
|
||||
monkeypatch.setattr(
|
||||
sys, "argv", ["close_low_quality_prs.py", "--limit", "2", "--close"]
|
||||
)
|
||||
rc = closer_module.main()
|
||||
assert rc == 0
|
||||
assert len(called) == 2
|
||||
|
||||
|
||||
class TestFetchOpenPrsLimitWarning:
|
||||
"""`fetch_open_prs` must surface a warning when the gh CLI cap is hit."""
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue