Skip to content

[duplicate-code] Duplicate Code Detected: Update entity safe-output jobs #5905

@github-actions

Description

@github-actions

🔍 Duplicate Code Detected: Update entity safe-output jobs

Analysis of commit e04d4f8

Assignee: @copilot

Summary

Repeated boilerplate for building update safe-output jobs (issue, pull request, release) duplicates environment setup, output wiring, and job conditions. Changes to job scaffolding (env vars, permissions, conditions) must be applied in multiple places, increasing drift risk.

Duplication Details

Pattern: Update entity job builder repetition

  • Severity: Medium
  • Occurrences: 3
  • Locations:
    • pkg/workflow/update_issue.go (lines 19-62)
    • pkg/workflow/update_pull_request.go (lines 18-65)
    • pkg/workflow/update_release.go (lines 16-50)
  • Code Sample:
// Pattern: validate config, build custom env vars, outputs, job condition, then call buildUpdateEntityJob
cfg := data.SafeOutputs.UpdateIssues
customEnvVars := []string{ ... }
customEnvVars = append(customEnvVars, BuildTargetEnvVar("GH_AW_UPDATE_TARGET", cfg.Target)...)
outputs := map[string]string{ ... }
jobCondition := BuildSafeOutputType("update_issue")
if cfg.Target == "" { jobCondition = buildAnd(jobCondition, BuildPropertyAccess(...)) }
params := UpdateEntityJobParams{ ... CustomEnvVars: customEnvVars, Outputs: outputs, Condition: jobCondition }
return c.buildUpdateEntityJob(data, mainJobName, &cfg.UpdateEntityConfig, params, updateIssueLog)

Similar blocks appear in PR and release builders with only entity-specific env/outputs differing, leading to copy-paste maintenance.

Impact Analysis

  • Maintainability: Three places to update when changing permissions, conditions, or env wiring for update jobs; easy to miss one.
  • Bug Risk: Inconsistent event-guard logic or output wiring between entities could regress updates (e.g., missing event check on one job).
  • Code Bloat: Extra boilerplate obscures the core differences between entity types.

Refactoring Recommendations

  1. Extract shared builder helper
    • Create a single helper that accepts entity-specific env var builder, outputs map, permissions, and event condition hook, and returns the configured job.
    • Suggested location: pkg/workflow/update_entity_helpers.go near existing update entity helpers.
    • Benefits: one place to adjust permissions/conditions; reduces copy-paste and drift.
  2. Centralize event-condition logic
    • Encapsulate the optional event guard (issue/PR vs release) inside the shared helper to avoid divergent logic.
  3. Table-driven configuration
    • Define per-entity metadata (config key, step name/id, outputs) in a small table and iterate to generate jobs, keeping only entity-specific flags (status/title/body) locally.

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: e04d4f8
  • Analysis Date: 2025-12-08

AI generated by Duplicate Code Detector

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions