🔍 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-39
pkg/workflow/update_discussion.go:18-51
pkg/workflow/update_pull_request.go:16-39
pkg/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 / parseUpdateReleaseConfig
Impact 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) *T that handles config allocation, parseUpdateEntityConfigWithFields, and base assignment, with an optional post-processor.
- Estimated effort: 1 hour; reduces boilerplate while keeping typed configs.
Implementation Checklist
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
🔍 Duplicate Code Detected: Update entity config parsers
Analysis of commit 0d020ce
Assignee:
@copilotSummary
Four
parseUpdate*functions inpkg/workflowrepeat the same setup-and-parse scaffold (create config, callparseUpdateEntityConfigWithFields, 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
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-32Impact Analysis
Refactoring Recommendations
Table-driven parser registration
Typed wrapper generator
buildUpdateEntityConfig[T any](opts UpdateEntityParseOptions) *Tthat handles config allocation,parseUpdateEntityConfigWithFields, and base assignment, with an optional post-processor.Implementation Checklist
Analysis Metadata