diff --git a/src/operations_center/entrypoints/custodian_sweep/main.py b/src/operations_center/entrypoints/custodian_sweep/main.py index b2bf78b7..a95f90cc 100644 --- a/src/operations_center/entrypoints/custodian_sweep/main.py +++ b/src/operations_center/entrypoints/custodian_sweep/main.py @@ -223,6 +223,8 @@ def _emit( title = f"[{sweep.repo_key}] custodian sweep: {sweep.total} findings" body = _render_body(sweep, deltas) existing = existing_tasks.get(sweep.repo_key) + if sweep.error is None and sweep.total == 0: + return "skipped-zero-findings" if not dry_run else "would-skip-zero-findings" if dry_run: return "would-comment" if existing else "would-create" if existing: diff --git a/tests/test_custodian_sweep.py b/tests/test_custodian_sweep.py index d45ee8c0..507b2ea4 100644 --- a/tests/test_custodian_sweep.py +++ b/tests/test_custodian_sweep.py @@ -18,6 +18,7 @@ _DEDUP_LABEL_PREFIX, _delta, _discover_targets, + _emit, _find_open_sweep_task, _index_open_sweep_tasks, _render_body, @@ -121,6 +122,43 @@ def test_index_open_sweep_tasks_maps_repo_key_to_issue() -> None: } +def test_emit_skips_zero_finding_repo_without_plane_calls() -> None: + calls: list[tuple[str, object]] = [] + + plane = SimpleNamespace( + comment_issue=lambda issue_id, body: calls.append(("comment", issue_id, body)), + create_issue=lambda **kwargs: calls.append(("create", kwargs)), + ) + + action = _emit( + _RepoSweep(repo_key="Demo", envelope=_envelope()), + {}, + plane, + existing_tasks={}, + dry_run=False, + ) + + assert action == "skipped-zero-findings" + assert calls == [] + + +def test_emit_dry_run_reports_zero_finding_skip() -> None: + plane = SimpleNamespace( + comment_issue=lambda issue_id, body: None, + create_issue=lambda **kwargs: None, + ) + + action = _emit( + _RepoSweep(repo_key="Demo", envelope=_envelope()), + {}, + plane, + existing_tasks={}, + dry_run=True, + ) + + assert action == "would-skip-zero-findings" + + def test_discover_targets_filters_to_repos_with_custodian_yaml(tmp_path: Path) -> None: has_yaml = tmp_path / "WithYaml" has_yaml.mkdir()