Skip to content

Refactor duplicated code across client and deduplication modules#2

Draft
Copilot wants to merge 2 commits intomainfrom
copilot/refactor-duplicate-code
Draft

Refactor duplicated code across client and deduplication modules#2
Copilot wants to merge 2 commits intomainfrom
copilot/refactor-duplicate-code

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Dec 21, 2025

Pylint detected significant code duplication: 50+ line _handle_error() methods duplicated across sync/async clients, identical _should_retry() logic, and 15+ lines of duplicate-finding code repeated in two scripts.

Changes

Created client_utils.py module

  • Extracted handle_error(response, endpoint) - converts HTTP errors to typed exceptions
  • Extracted should_retry(status_code) - determines retriable status codes
  • Removed duplicate methods from DexClient and AsyncDexClient

Added find_all_duplicates() to deduplication module

  • Convenience function encapsulating email, phone, name+title, and fuzzy name matching
  • Returns (matches, clusters) tuple for consistent access pattern
  • Replaced duplicate logic in flag_duplicates.py and resolve_duplicates.py

Example usage:

# Before: Scripts duplicated 15+ lines of detection logic
matches = []
matches.extend(find_email_duplicates(conn))
matches.extend(find_phone_duplicates(conn))
matches.extend(find_name_and_title_duplicates(conn))
matches.extend(find_fuzzy_name_duplicates(conn, threshold=0.98))
clusters = cluster_duplicates(matches)

# After: Single function call
matches, clusters = find_all_duplicates(conn, fuzzy_threshold=0.98)

Impact

  • 189 lines of duplicate code removed
  • 89 lines of shared utilities added
  • 22 new unit tests added for utilities (182 total tests passing)
  • Remaining duplications are minimal endpoint-specific patterns in paginated GET methods
Original prompt

Find and refactor duplicated code


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Dec 21, 2025

Important

Review skipped

Bot user detected.

To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.


Comment @coderabbitai help to get the list of available commands and usage tips.

Co-authored-by: domfahey <789732+domfahey@users.noreply.github.com>
Copilot AI changed the title [WIP] Refactor duplicated code across the project Refactor duplicated code across client and deduplication modules Dec 21, 2025
Copilot AI requested a review from domfahey December 21, 2025 14:12
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