Skip to content

[duplicate-code] Go update-entity config parsing duplicated across issue/PR/release #6890

@github-actions

Description

@github-actions

🔍 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-61
    • pkg/workflow/update_pull_request.go:16-61
    • pkg/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

  1. 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, parseUpdateEntityConfig call, nil check) into one reusable function.
    • Estimated effort: 1-2h; benefits: single point of change for all update entity parsers.
  2. 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

Metadata

Metadata

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions