Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/operations_center/entrypoints/custodian_sweep/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
41 changes: 41 additions & 0 deletions tests/test_custodian_sweep.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
_DEDUP_LABEL_PREFIX,
_delta,
_discover_targets,
_emit,
_find_open_sweep_task,
_index_open_sweep_tasks,
_render_body,
Expand Down Expand Up @@ -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()
Expand Down
Loading