Skip to content

[duplicate-code] Duplicate Code: update entity config parsers share identical scaffolding #7918

@github-actions

Description

@github-actions

🔍 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

  1. 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.
  2. 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

  • 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

Metadata

Metadata

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions