Skip to content

Refactor: Extract helpers to eliminate duplication (89 lines)#47

Merged
wham merged 7 commits intomainfrom
copilot/refactor-reduce-code-duplication
Dec 20, 2025
Merged

Refactor: Extract helpers to eliminate duplication (89 lines)#47
wham merged 7 commits intomainfrom
copilot/refactor-reduce-code-duplication

Conversation

Copy link
Contributor

Copilot AI commented Dec 20, 2025

Extracted repeated patterns into focused helper functions to reduce duplication across error handling, HTTP header parsing, and UI updates.

Changes

Helper functions (7 added)

  • parseHeaderInt - Consolidates header→int conversion (4 call sites)
  • updateProgressStatus - Unifies rate limit + API status updates (8 call sites)
  • Error handling suite: logErrorAndReturn, exitAfterDelay, handleFatalError, handlePullItemError, checkPreviousFailures

Simplified logic

  • updateRateLimitInfo: Replaced 4 if-blocks with parseHeaderInt calls
  • PopulateSearchTable: Extracted 3 identical index operations into indexTable closure
  • ClearData: Switch statement → map lookup, unified deletion loop
  • Item flag processing: Switch → map for boolean lookups
  • Gradient colors: Extracted duplicate 6-color array to global

Example - Before/After error handling:

// Before: Repeated at 6+ call sites
if err != nil {
    progress.Log("Error: %v", err)
    time.Sleep(3 * time.Second)
    progress.Stop()
    os.Exit(1)
}

// After: Single call
if err != nil {
    handleFatalError(progress, "Error: %v", err)
}

5782 → 5693 lines. No functional changes.

Original prompt

Carefully inspect the code and look for opportunities to remove duplication or make it shorter and more concise without any loss of functionality.


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

Copilot AI and others added 5 commits December 20, 2025 04:40
- Add parseHeaderInt helper to simplify header parsing
- Add updateProgressStatus helper to consolidate rate limit/status updates
- Add error handling helpers (logErrorAndReturn, handleFatalError, etc.)
- Refactor PopulateSearchTable to use indexTable helper
- Simplify updateRateLimitInfo using parseHeaderInt
- Replace 60+ lines of duplicated error handling with helpers
- Reduced code from 5782 to 5713 lines (69 line reduction)

Co-authored-by: wham <448809+wham@users.noreply.github.com>
- Move duplicate gradient color definitions to global variable
- Reduced duplication in newModel and newLoginModel
- Removed 16 lines of duplicate color definitions
- Further reduced from 5713 to 5704 lines

Co-authored-by: wham <448809+wham@users.noreply.github.com>
- Replace switch statements with map lookups for item flags
- Consolidate ClearData function logic using map and shared loop
- More concise and maintainable item processing
- Reduced from 5704 to 5684 lines (20 line reduction)
- Total reduction: 98 lines from original 5782

Co-authored-by: wham <448809+wham@users.noreply.github.com>
- Fix indentation of updateProgressStatus calls and comments
- Separate misplaced comment onto correct line
- Address all code review feedback
- Code still builds successfully

Co-authored-by: wham <448809+wham@users.noreply.github.com>
- Add new helper function for cases where errors are already logged
- Replace handleFatalError("") with exitAfterDelay for clearer intent
- Improves code readability and addresses code review feedback
- Line count: 5693 (still 89 lines reduction from original 5782)

Co-authored-by: wham <448809+wham@users.noreply.github.com>
Copilot AI changed the title [WIP] Refactor code to remove duplication and enhance conciseness Refactor: Extract helpers to eliminate duplication (89 lines) Dec 20, 2025
Copilot AI requested a review from wham December 20, 2025 04:58
@wham wham marked this pull request as ready for review December 20, 2025 05:27
@wham wham added the minor label Dec 20, 2025
@wham wham merged commit 5377241 into main Dec 20, 2025
6 checks passed
@wham wham deleted the copilot/refactor-reduce-code-duplication branch December 20, 2025 05:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants