diff --git a/cli/meta/ci/report_failures.py b/cli/meta/ci/report_failures.py index b8721a80a7..2121f104a4 100644 --- a/cli/meta/ci/report_failures.py +++ b/cli/meta/ci/report_failures.py @@ -148,19 +148,21 @@ def _existing_issue(repo: str, role: str) -> int | None: return None -def report(run_id: str, repo: str) -> int: - jobs = json.loads( - _gh( - [ - "api", - "--paginate", - f"repos/{repo}/actions/runs/{run_id}/jobs", - "--jq", - "[.jobs[] | {name, conclusion}]", - ] - ) - or "[]" +def list_jobs(run_id: str, repo: str) -> list[dict]: + out = _gh( + [ + "api", + "--paginate", + f"repos/{repo}/actions/runs/{run_id}/jobs", + "--jq", + ".jobs[] | {name, conclusion}", + ] ) + return [json.loads(line) for line in out.splitlines() if line.strip()] + + +def report(run_id: str, repo: str) -> int: + jobs = list_jobs(run_id, repo) roles = failed_roles(jobs) if not roles: print("No failed deploy roles.") diff --git a/tests/unit/python/cli/meta/ci/test_report_failures.py b/tests/unit/python/cli/meta/ci/test_report_failures.py index 557e2bcdd3..f5a0627373 100644 --- a/tests/unit/python/cli/meta/ci/test_report_failures.py +++ b/tests/unit/python/cli/meta/ci/test_report_failures.py @@ -3,6 +3,7 @@ from __future__ import annotations import tempfile import unittest from pathlib import Path +from unittest.mock import patch from cli.meta.ci.report_failures import ( Failure, @@ -10,6 +11,7 @@ from cli.meta.ci.report_failures import ( decisive_excerpt, failed_roles, issue_body, + list_jobs, ) @@ -80,6 +82,19 @@ class TestReportFailures(unittest.TestCase): artifact_name("web-app-x", Failure("compose", "0", True, "fedora", "zfs")), ) + def test_list_jobs_reads_one_job_per_line_across_pages(self) -> None: + pages = ( + '{"name": "deploy a", "conclusion": "success"}\n' + '{"name": "deploy b", "conclusion": "failure"}\n' + ) + with patch("cli.meta.ci.report_failures._gh", return_value=pages): + jobs = list_jobs("1", "owner/repo") + self.assertEqual([job["name"] for job in jobs], ["deploy a", "deploy b"]) + + def test_list_jobs_of_an_empty_listing_is_empty(self) -> None: + with patch("cli.meta.ci.report_failures._gh", return_value=""): + self.assertEqual(list_jobs("1", "owner/repo"), []) + def test_issue_body_lists_failures_and_run(self) -> None: body = issue_body( "web-app-xwiki",