-
Notifications
You must be signed in to change notification settings - Fork 217
Closed
Description
🔍 Duplicate Code Detected: Update entity config parsers
Analysis of commit 0d020ce
Assignee: @copilot
Summary
Four parseUpdate* functions in pkg/workflow repeat the same setup-and-parse scaffold (create config, call parseUpdateEntityConfigWithFields, copy base config) with only small option differences. The repetition makes it easy for defaults or logging to drift across entity types.
Duplication Details
Pattern: Repeated update-entity parser scaffolding
- Severity: Medium
- Occurrences: 4
- Locations:
pkg/workflow/update_issue.go:17-39pkg/workflow/update_discussion.go:18-51pkg/workflow/update_pull_request.go:16-39pkg/workflow/update_release.go:14-32
- Code Sample:
func (c *Compiler) parseUpdateIssuesConfig(outputMap map[string]any) *UpdateIssuesConfig {
cfg := &UpdateIssuesConfig{}
baseConfig, _ := c.parseUpdateEntityConfigWithFields(outputMap, UpdateEntityParseOptions{ /* entity-specific fields */ })
if baseConfig == nil { return nil }
cfg.UpdateEntityConfig = *baseConfig
return cfg
}
// Same scaffold in parseUpdateDiscussionsConfig / parseUpdatePullRequestsConfig / parseUpdateReleaseConfigImpact Analysis
- Maintainability: Adding new update targets or adjusting defaults requires editing four near-identical functions, increasing drift risk (e.g., logging, default field parsing modes, max limits).
- Bug Risk: Inconsistent parsing options (bool vs key existence) could emerge if one copy is updated and others are missed.
- Code Bloat: Repeated ~20-line blocks inflate compiler code and obscure the small differences between entity types.
Refactoring Recommendations
-
Table-driven parser registration
- Extract a generic helper that accepts an entity descriptor (config key, logger, field specs, optional custom parser) and returns the typed config, reducing each entity to descriptor data.
- Estimated effort: 1-2 hours; simplifies adding future entities and keeps defaults consistent.
- Benefits: Single place to adjust parsing defaults/logging; clearer diff between entities.
-
Typed wrapper generator
- Alternatively, add a small builder like
buildUpdateEntityConfig[T any](opts UpdateEntityParseOptions) *Tthat handles config allocation,parseUpdateEntityConfigWithFields, and base assignment, with an optional post-processor. - Estimated effort: 1 hour; reduces boilerplate while keeping typed configs.
- Alternatively, add a small builder like
Implementation Checklist
- Review duplication findings
- Prioritize refactoring tasks
- Create refactoring plan
- Implement changes
- Update tests
- Verify no functionality broken
Analysis Metadata
- Analyzed Files: 4
- Detection Method: Serena semantic code analysis
- Commit: 0d020ce
- Analysis Date: 2025-12-27T19:28:27Z
AI generated by Duplicate Code Detector
Reactions are currently unavailable