Skip to content

Refactor: Deduplicate shared code across modules - #3

Open
Chocapikk wants to merge 1 commit into
Christbowel:mainfrom
Chocapikk:refactor-dedup
Open

Refactor: Deduplicate shared code across modules#3
Chocapikk wants to merge 1 commit into
Christbowel:mainfrom
Chocapikk:refactor-dedup

Conversation

@Chocapikk

Copy link
Copy Markdown
Contributor

Summary

  • New src/github_api.py: github_get() was copy-pasted between deep_scan.py and silent_scan.py with slight formatting differences. Extracted into a single module.
  • score_with_fingerprints() in fingerprint.py: The fingerprint scoring block (combine patches, match, compute normalized score) was duplicated in both scanners. Now a single function.
  • build_analysis_result() in analyze.py: The 17-field result dict was built identically in analyze.py and backfill_local.py with a duplicated _str() helper. Now shared.
  • _enrich_advisory() in render.py: The _clean_text/_clean_diff enrichment loop was repeated in render_daily_patch, render_readme, and render_html_index. Now a single function.
  • Ruff cleanup: unused imports and f-strings without placeholders across 11 files.
  • Bug fix: suspects_count undefined variable in deep_scan.py (also fixed in PR Fix: Crash in deep_scan, validate LLM output, ruff cleanup #1, included here for branch independence).

Impact

  • -96 net lines (135 added, 187 removed)
  • No behavior changes, no threshold changes, no pattern changes
  • Any future fix to github_get(), scoring, or result building only needs to happen in one place

Test plan

  • ruff check src/ passes with 0 errors
  • Run python -m src.silent_scan - verify it imports and runs
  • Run python -m src.deep_scan owner/repo --since 2025-01-01 --max 10 - verify scoring works

- Extract github_get() into src/github_api.py (was duplicated in deep_scan.py and silent_scan.py)
- Extract score_with_fingerprints() into fingerprint.py (scoring logic duplicated in both scanners)
- Extract build_analysis_result() into analyze.py (result building duplicated in backfill_local.py)
- Extract _enrich_advisory() in render.py (cleaning logic repeated in 3 render functions)
- Fix undefined suspects_count crash in deep_scan.py
- Ruff cleanup: unused imports, f-strings without placeholders across 11 files
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.

1 participant