Skip to content

Commit e26ee40

Browse files
committed
ci: Trim whitespace from --ignore-checks input
- Update logic to handle whitespace in `--ignore-checks` argument. - Add unit tests to verify functionality with various whitespace cases. Signed-off-by: Helber Belmiro <helber.belmiro@gmail.com>
1 parent d4df3e3 commit e26ee40

File tree

2 files changed

+58
-1
lines changed

2 files changed

+58
-1
lines changed

.github/scripts/ci_checks/ci_checks.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ def main(argv: list[str] | None = None) -> int:
166166
return 0
167167

168168
check_run_id = gh.get_own_check_run_id(args.repo, args.head_sha, args.check_name)
169-
ignore_checks = frozenset(name for name in args.ignore_checks.split(",") if name)
169+
ignore_checks = frozenset(name.strip() for name in args.ignore_checks.split(",") if name.strip())
170170

171171
try:
172172
wait_for_checks(

.github/scripts/ci_checks/tests/test_ci_checks.py

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,27 @@ def test_ignore_checks_excludes_named_checks(self):
308308
ignore_checks=frozenset({"Agent"}),
309309
)
310310

311+
def test_ignore_checks_excludes_multiple_named_checks(self):
312+
"""Multiple checks listed in ignore_checks are all excluded."""
313+
gh = MagicMock(spec=GhClient)
314+
gh.get_check_runs.return_value = json.loads(
315+
_api_response(
316+
_make_check_run(100, "lint", "completed", "success"),
317+
_make_check_run(200, "Agent", "in_progress"),
318+
_make_check_run(300, "CodeQL", "in_progress"),
319+
)
320+
)
321+
wait_for_checks(
322+
gh,
323+
"owner/repo",
324+
"abc123",
325+
check_run_id=999,
326+
delay=0,
327+
retries=1,
328+
interval=0,
329+
ignore_checks=frozenset({"Agent", "CodeQL"}),
330+
)
331+
311332
def test_mixed_passing_statuses(self):
312333
"""Mixed success, neutral, and skipped -- all treated as passing."""
313334
gh = MagicMock(spec=GhClient)
@@ -738,6 +759,42 @@ def test_dependabot_pr_runs_checks_and_saves_payload(self, mock_gh_client_cls, t
738759
assert result == 0
739760
assert Path(output_dir, "pr_number").read_text().strip() == "10"
740761

762+
@patch("ci_checks.ci_checks.GhClient")
763+
def test_ignore_checks_with_whitespace(self, mock_gh_client_cls, tmp_path):
764+
"""--ignore-checks trims whitespace so 'Agent, CodeQL' works correctly."""
765+
all_pass_with_agent = [
766+
json.loads(
767+
_api_response(
768+
_make_check_run(999, "check_ci_status", "in_progress"),
769+
_make_check_run(100, "lint", "completed", "success"),
770+
_make_check_run(200, "Agent", "in_progress"),
771+
_make_check_run(300, "CodeQL", "in_progress"),
772+
)
773+
),
774+
]
775+
fake = FakeGhClient(check_runs_responses=all_pass_with_agent)
776+
mock_gh_client_cls.return_value = fake
777+
output_dir = str(tmp_path / "pr")
778+
result = main(
779+
[
780+
"--pr-number",
781+
"10",
782+
"--event-action",
783+
"opened",
784+
"--labels",
785+
"",
786+
"--author-association",
787+
"MEMBER",
788+
"--output-dir",
789+
output_dir,
790+
*self._BASE_ARGS,
791+
"--ignore-checks",
792+
" Agent , CodeQL ",
793+
]
794+
)
795+
assert result == 0
796+
assert Path(output_dir, "pr_number").exists()
797+
741798
@patch("ci_checks.ci_checks.GhClient")
742799
def test_wait_for_checks_failure_prevents_payload_save(self, mock_gh_client_cls, tmp_path):
743800
"""When checks fail, exit non-zero and do NOT save payload."""

0 commit comments

Comments
 (0)