Skip to content

refactor: dedupe ecosystem dispatch, telemetry, API client, cleanup, get#88

Merged
Mikola Lysenko (mikolalysenko) merged 2 commits into
mainfrom
cleanup
May 27, 2026
Merged

refactor: dedupe ecosystem dispatch, telemetry, API client, cleanup, get#88
Mikola Lysenko (mikolalysenko) merged 2 commits into
mainfrom
cleanup

Conversation

@mikolalysenko
Copy link
Copy Markdown
Collaborator

Summary

Net ~718 lines removed across six files in the two core crates. No behavior changes; no public API breakage; all 1308 tests pass with no new warnings.

  • ecosystem_dispatch.rs (953 → 556): macro-extracted the 8 per-ecosystem scan blocks duplicated between `find_packages_for_purls` and `find_packages_for_rollback`; the two functions now share a `dispatch_find` core that takes a `pypi_merge` callback for the only meaningful divergence.
  • `commands/get.rs` (1901 → 1767): hoisted `report_error` / `print_json` / `empty_result_json` / `report_fetch_failure` / `write_all_patch_blobs` / `vulnerabilities_for_manifest` / `build_patch_record`; folded the three identical CVE/GHSA/PURL search match arms into one dispatch.
  • `utils/telemetry.rs` (1107 → 1027): replaced ~18 hand-built `HashMap<String, Value>` constructions with a single `fire()` helper plus `serde_json::json!({...})` literals; each per-event tracker is now 3–5 lines instead of 10–20.
  • `api/client.rs` (1336 → 1322): collapsed `search_patches_by_cve` / `by_ghsa` / `by_package` into a shared `search_patches_by_route(route, identifier)`.
  • `api/blob_fetcher.rs` (871 → 833): derived `Default` for `FetchMissingBlobsResult`, introduced `all_failed_result` for the three blocker-on-mkdir branches, removed the redundant `empty_result()` helper.
  • `utils/cleanup_blobs.rs` (585 → 540): unified `cleanup_unused_blobs` / `cleanup_unused_archives` behind a `cleanup_dir(dir, dry_run, is_used)` core taking a closure for the per-file "is this still in use" check.

Test plan

  • `cargo test --features cargo` — 499 lib tests + all integration tests pass
  • `cargo test --features "cargo golang maven composer nuget deno"` — all tests pass under every feature gate
  • `cargo build --tests --features "cargo golang maven composer nuget deno"` — no new warnings (only the two pre-existing snake_case warnings in `crawler_maven_e2e.rs`)
  • CI on the PR

🤖 Generated with Claude Code

…b helpers

Net ~718 lines removed across six files; all 1308 tests still pass.

- ecosystem_dispatch.rs: macro-extract the 8 per-ecosystem scan blocks
  duplicated between find_packages_for_purls and find_packages_for_rollback;
  share a dispatch_find core with a pypi_merge callback for the only real
  divergence
- commands/get.rs: hoist report_error / print_json / empty_result_json /
  report_fetch_failure / write_all_patch_blobs / vulnerabilities_for_manifest
  / build_patch_record; fold the three CVE/GHSA/PURL search arms into one
  dispatch
- utils/telemetry.rs: replace ~18 hand-built HashMap<String, Value>
  constructions with a fire() helper plus serde_json::json!({...}) literals
- api/client.rs: collapse search_patches_by_{cve,ghsa,package} behind a
  shared search_patches_by_route(route, identifier)
- api/blob_fetcher.rs: derive Default for FetchMissingBlobsResult; share an
  all_failed_result helper for the three mkdir-blocker branches
- utils/cleanup_blobs.rs: unify cleanup_unused_blobs / cleanup_unused_archives
  behind a cleanup_dir(dir, dry_run, is_used) core

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
`-D clippy::type_complexity` rejected the inline fn-pointer signature on
`dispatch_find`'s `pypi_merge` argument. Lift it to a `MergeFn` type alias
shared by `merge_first_wins` and `merge_pypi_qualified`.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@mikolalysenko Mikola Lysenko (mikolalysenko) merged commit 3835974 into main May 27, 2026
42 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants