Refactor: Deduplicate shared code across modules - #3
Open
Chocapikk wants to merge 1 commit into
Open
Conversation
- 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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
src/github_api.py:github_get()was copy-pasted betweendeep_scan.pyandsilent_scan.pywith slight formatting differences. Extracted into a single module.score_with_fingerprints()infingerprint.py: The fingerprint scoring block (combine patches, match, compute normalized score) was duplicated in both scanners. Now a single function.build_analysis_result()inanalyze.py: The 17-field result dict was built identically inanalyze.pyandbackfill_local.pywith a duplicated_str()helper. Now shared._enrich_advisory()inrender.py: The_clean_text/_clean_diffenrichment loop was repeated inrender_daily_patch,render_readme, andrender_html_index. Now a single function.suspects_countundefined variable indeep_scan.py(also fixed in PR Fix: Crash in deep_scan, validate LLM output, ruff cleanup #1, included here for branch independence).Impact
github_get(), scoring, or result building only needs to happen in one placeTest plan
ruff check src/passes with 0 errorspython -m src.silent_scan- verify it imports and runspython -m src.deep_scan owner/repo --since 2025-01-01 --max 10- verify scoring works