-
Notifications
You must be signed in to change notification settings - Fork 77
Closed
Description
🔍 Duplicate Code Detected: Update entity config parsers
Analysis of commit a2389f6
Assignee: @copilot
Summary
Three separate config parsers for update-issue, update-pull-request, and update-release replicate the same setup/tear-down logic (building UpdateEntityJobParams, calling parseUpdateEntityConfig, and re-wrapping the result) with minor per-entity tweaks. The shared scaffolding is ~15+ lines repeated, increasing maintenance overhead when adding new update entities or changing parsing behavior.
Duplication Details
Pattern: Repeated update config scaffolding
- Severity: Medium
- Occurrences: 3
- Locations:
pkg/workflow/update_issue.go:17-61pkg/workflow/update_pull_request.go:16-61pkg/workflow/update_release.go:14-31
- Code Sample:
params := UpdateEntityJobParams{EntityType: UpdateEntityIssue, ConfigKey: "update-issue"}
baseConfig := c.parseUpdateEntityConfig(outputMap, params, updateIssueLog, parseSpecificFields)
if baseConfig == nil {
return nil
}
updateIssuesConfig := &UpdateIssuesConfig{UpdateEntityConfig: *baseConfig}(Same scaffold appears in update-pull-request and update-release with only names changed.)
Impact Analysis
- Maintainability: Shared logic must be edited in three places when adding defaults, logging, or validation changes for update entities.
- Bug Risk: Subtle differences (e.g., logging, nil handling) can diverge across entity types, causing inconsistent parsing or silent failures.
- Code Bloat: Extra boilerplate obscures the per-entity differences (fields and toggles) and makes onboarding harder.
Refactoring Recommendations
- Extract a generic helper (e.g.,
parseUpdateEntity(outputMap, params, logger, parseFields)or table-driven config) returning the typed config struct to remove repeated scaffolding.- Extract common setup (
UpdateEntityJobParams,parseUpdateEntityConfigcall, nil check) into one reusable function. - Estimated effort: 1-2h; benefits: single point of change for all update entity parsers.
- Extract common setup (
- Encapsulate per-entity field parsing via callbacks or a small descriptor map (e.g., booleans for
status,title,body) to reduce bespoke code paths.
Implementation Checklist
- Review duplication findings
- Prioritize refactoring tasks
- Create refactoring plan
- Implement changes
- Update tests
- Verify no functionality broken
Analysis Metadata
- Analyzed Files: 3
- Detection Method: Serena semantic code analysis
- Commit: a2389f6
- Analysis Date: 2025-01-06
AI generated by Duplicate Code Detector
Reactions are currently unavailable