Skip to content

Commit 27bb72e

Browse files
fix: stop workflow-run pagination at --since boundary before conclusion filter (#1248)
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 6403339 commit 27bb72e

2 files changed

Lines changed: 27 additions & 2 deletions

File tree

scripts/fetch-workflow-logs.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,11 +87,11 @@ def list_workflow_runs(repo: str, workflow: str, token: str, since: str | None,
8787
runs = []
8888
for batch in _iter_workflow_run_pages(repo=repo, workflow=workflow, token=token):
8989
for run in batch:
90-
if not _run_matches_conclusion(run, conclusion):
91-
continue
9290
if _is_before_since_boundary(run, since):
9391
# Runs are sorted newest-first; once we go past since, stop paging
9492
return runs
93+
if not _run_matches_conclusion(run, conclusion):
94+
continue
9595
if _is_after_until_boundary(run, until_normalized):
9696
continue
9797
runs.append(run)

tests/test_fetch_workflow_logs.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,31 @@ def fake_github_api(path, token, accept="application/vnd.github+json"):
3939
assert len(calls) == 2
4040

4141

42+
def test_list_workflow_runs_stops_at_since_boundary_before_conclusion_filter(monkeypatch):
43+
module = _load_module()
44+
calls = []
45+
46+
def fake_github_api(path, token, accept="application/vnd.github+json"):
47+
calls.append(path)
48+
if path.endswith("page=1"):
49+
return b'{"workflow_runs":[{"id":101,"created_at":"2024-12-31T00:00:00Z","conclusion":"success"}]}'
50+
return b'{"workflow_runs":[{"id":100,"created_at":"2024-12-30T00:00:00Z","conclusion":"failure"}]}'
51+
52+
monkeypatch.setattr(module, "github_api", fake_github_api)
53+
runs = module.list_workflow_runs(
54+
repo="elastic/ai-github-actions",
55+
workflow="ci.yml",
56+
token="x",
57+
since="2025-01-01T00:00:00Z",
58+
until=None,
59+
conclusion="failure",
60+
last=20,
61+
)
62+
63+
assert runs == []
64+
assert len(calls) == 1
65+
66+
4267
def test_list_workflow_runs_inclusive_date_only_until(monkeypatch):
4368
module = _load_module()
4469

0 commit comments

Comments
 (0)