Skip to content

[duplicate-code] Update issue/PR scripts duplicate workflow scaffolding #5131

@github-actions

Description

@github-actions

🔍 Duplicate Code Detected: Update Workflow Scripts

Analysis of commit faacd5c

Assignee: @copilot

Summary

pkg/workflow/js/update_issue.cjs and pkg/workflow/js/update_pull_request.cjs are almost identical copies of the same workflow scaffolding: they redefine context detection, staged preview rendering, execution, summary generation, and the runUpdateWorkflow invocation even though both ultimately call the same helper in update_runner.cjs. More than 150 lines per file differ only in strings ("issue" vs "pull request") or the REST endpoint that is hit.

Duplication Details

Pattern: Duplicate staged update workflow wrappers

  • Severity: Medium
  • Occurrences: 2 (issue + PR updates)
  • Locations:
    • pkg/workflow/js/update_issue.cjs:6-100
    • pkg/workflow/js/update_pull_request.cjs:6-150
  • Code Sample:
    async function main() {
      return await runUpdateWorkflow({
        itemType: "update_issue",
        displayName: "issue",
        displayNamePlural: "issues",
        numberField: "issue_number",
        outputNumberKey: "issue_number",
        outputUrlKey: "issue_url",
        isValidContext: isIssueContext,
        getContextNumber: getIssueNumber,
        supportsStatus: true,
        supportsOperation: false,
        renderStagedItem,
        executeUpdate: executeIssueUpdate,
        getSummaryLine,
      });
    }
    The update_pull_request version is the same block with only label names and supportsOperation toggled. Supporting helpers (renderStagedItem, is*Context, get*Number, getSummaryLine) are also copy/paste with trivial text changes.

Impact Analysis

  • Maintainability: Any change to staged preview formatting, summary wording, or run metadata must be implemented in both files manually.
  • Bug Risk: Divergence is already visible—PR updates add AI-attribution footers while issues don't—because the shared logic lives in separate copies.
  • Code Bloat: Adds ~200 LoC of boilerplate and makes it harder to spot the genuinely different pieces (body operations vs status updates).

Refactoring Recommendations

  1. Parameterize runUpdateWorkflow
    • Instead of duplicating wrapper files, export metadata objects (labels, field support, REST handler) and feed them into a shared factory (e.g., registerUpdateWorkflow({ entity: "issue", ... })).
    • Estimated effort: 4 hours.
    • Benefit: ensures staged previews, summary format, and context validation stay consistent.
  2. Share context helpers
    • Move isIssueContext/isPRContext + number extraction into update_runner.cjs or a context_detectors.cjs module so other update types can reuse them without new copies.
    • Estimated effort: 2 hours.

Implementation Checklist

  • Review duplication findings
  • Prioritize refactoring tasks
  • Create refactoring plan
  • Implement changes
  • Update tests
  • Verify no functionality broken

Analysis Metadata

  • Analyzed Files: 335 changed .go/.cjs files (deep dive on new update scripts)
  • Detection Method: Serena semantic code analysis + side-by-side review
  • Commit: faacd5c
  • Analysis Date: 2025-11-30

AI generated by Duplicate Code Detector

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions