Skip to content

refactor: extract shared utilities for duplicated code patterns - #3

Open
devin-ai-integration[bot] wants to merge 1 commit into
mainfrom
devin/1782500165-refactor-shared-utilities
Open

refactor: extract shared utilities for duplicated code patterns#3
devin-ai-integration[bot] wants to merge 1 commit into
mainfrom
devin/1782500165-refactor-shared-utilities

Conversation

@devin-ai-integration

Copy link
Copy Markdown

Summary

Four duplicated code patterns consolidated into shared utilities:

1. BinaryDetection (new dev.jleak.util.BinaryDetection)
WorkerContext.looksBinary() and GitPreCommit.looksBinary() had identical binary-sniff logic (the latter even commented "duplicated here"). Both now delegate to:

BinaryDetection.looksBinary(byte[] data, int byteCount, int sniffBytes, double ratio)

2. LineContext.column(int matchStart) (new method)
The column calculation columnOffset + matchStart + 1 was repeated in RegexDetector.detect() and EntropyDetector.detect(). Now:

ctx.column(matchStart)  // returns columnOffset + matchStart + 1

3. Finding.from(SecretType, LineContext, ...) (new factory)
All three finding-creation sites (RegexDetector, EntropyDetector, Scanner PEM path) repeated new Finding(type, type.defaultSeverity(), ctx.file, ctx.lineNumber, ctx.columnOffset + start + 1, ...). Now:

Finding.from(type, ctx, matchStart, length, redacted, entropy)

4. ProcessRunner (new dev.jleak.util.ProcessRunner)
exec() and readAll() extracted from GitPreCommit into a reusable utility for subprocess execution, removing ~30 lines of private helpers.

Link to Devin session: https://app.devin.ai/sessions/cd46b49f4b6c4b37a74983b202dd7615
Requested by: @MrGoodNice

…tion, and process execution

- BinaryDetection: extract duplicated binary sniff logic from WorkerContext
  and GitPreCommit into dev.jleak.util.BinaryDetection
- LineContext.column(): add helper to encapsulate the repeated
  columnOffset + matchStart + 1 calculation used by all detectors
- Finding.from(): add factory method that derives column from LineContext
  and uses type.defaultSeverity(), replacing boilerplate in RegexDetector,
  EntropyDetector, and Scanner (PEM detection)
- ProcessRunner: extract exec/readAll from GitPreCommit into reusable
  dev.jleak.util.ProcessRunner utility

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@MrGoodNice MrGoodNice self-assigned this Jun 26, 2026
@devin-ai-integration

Copy link
Copy Markdown
Author

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment, CI, and merge conflict monitoring

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