Skip to content
Merged
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 not sweep.error 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
25 changes: 25 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 @@ -96,6 +97,30 @@ def test_find_open_sweep_task_returns_none_when_absent() -> None:
assert _find_open_sweep_task(plane, "Demo") is None


def test_emit_skips_plane_mutation_for_zero_findings() -> None:
plane = SimpleNamespace(
comment_issue=lambda *args, **kwargs: (_ for _ in ()).throw(AssertionError("unexpected")),
create_issue=lambda *args, **kwargs: (_ for _ in ()).throw(AssertionError("unexpected")),
)
sweep = _RepoSweep(repo_key="Demo", envelope=_envelope())

action = _emit(sweep, {}, plane, existing_tasks={}, dry_run=False)

assert action == "skipped-zero-findings"


def test_emit_still_reports_zero_findings_skip_in_dry_run() -> None:
plane = SimpleNamespace(
comment_issue=lambda *args, **kwargs: (_ for _ in ()).throw(AssertionError("unexpected")),
create_issue=lambda *args, **kwargs: (_ for _ in ()).throw(AssertionError("unexpected")),
)
sweep = _RepoSweep(repo_key="Demo", envelope=_envelope())

action = _emit(sweep, {}, plane, existing_tasks={}, dry_run=True)

assert action == "skipped-zero-findings"


def test_index_open_sweep_tasks_maps_repo_key_to_issue() -> None:
plane = SimpleNamespace(
list_issues=lambda: [
Expand Down
Loading