diff --git a/src/operations_center/entrypoints/custodian_sweep/main.py b/src/operations_center/entrypoints/custodian_sweep/main.py index b2bf78b7..1a1d8ddb 100644 --- a/src/operations_center/entrypoints/custodian_sweep/main.py +++ b/src/operations_center/entrypoints/custodian_sweep/main.py @@ -220,6 +220,8 @@ def _emit( dry_run: bool, ) -> str: """Create-or-comment one Plane task per repo. Returns action label.""" + if sweep.error is None and sweep.total == 0: + return "skipped-zero-findings" title = f"[{sweep.repo_key}] custodian sweep: {sweep.total} findings" body = _render_body(sweep, deltas) existing = existing_tasks.get(sweep.repo_key) diff --git a/tests/test_custodian_sweep.py b/tests/test_custodian_sweep.py index d45ee8c0..bc5a51a6 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,46 @@ def test_index_open_sweep_tasks_maps_repo_key_to_issue() -> None: } +def test_emit_skips_plane_mutation_for_zero_findings() -> None: + calls: list[tuple[str, object]] = [] + + plane = SimpleNamespace( + comment_issue=lambda *args, **kwargs: calls.append(("comment", args)), + create_issue=lambda **kwargs: calls.append(("create", kwargs)), + ) + + action = _emit( + _RepoSweep(repo_key="Demo", envelope=_envelope()), + {}, + plane, + existing_tasks={"Demo": {"id": "123"}}, + dry_run=False, + ) + + assert action == "skipped-zero-findings" + assert calls == [] + + +def test_emit_skips_plane_mutation_for_zero_findings_in_dry_run() -> None: + calls: list[tuple[str, object]] = [] + + plane = SimpleNamespace( + comment_issue=lambda *args, **kwargs: calls.append(("comment", args)), + create_issue=lambda **kwargs: calls.append(("create", kwargs)), + ) + + action = _emit( + _RepoSweep(repo_key="Demo", envelope=_envelope()), + {}, + plane, + existing_tasks={}, + dry_run=True, + ) + + assert action == "skipped-zero-findings" + assert calls == [] + + def test_discover_targets_filters_to_repos_with_custodian_yaml(tmp_path: Path) -> None: has_yaml = tmp_path / "WithYaml" has_yaml.mkdir()