Skip to content

[duplicate-code] CJS update workflows duplicate runUpdateWorkflow scaffolding for issue and PR #6891

@github-actions

Description

@github-actions

🔍 Duplicate Code Detected: CJS update workflow scaffolding

Analysis of commit a2389f6

Assignee: @copilot

Summary

update_issue.cjs and update_pull_request.cjs both reimplement the same workflow scaffolding—imports, staged preview renderer creation, summary line factory, and the runUpdateWorkflow invocation with only small option differences. The repeated block spans ~20 lines in each file and could be centralized to reduce drift.

Duplication Details

Pattern: Reused update workflow wrapper

  • Severity: Medium
  • Occurrences: 2
  • Locations:
    • pkg/workflow/js/update_issue.cjs:4-58
    • pkg/workflow/js/update_pull_request.cjs:4-94
  • Code Sample:
const { runUpdateWorkflow, createRenderStagedItem, createGetSummaryLine } = require("./update_runner.cjs");
const renderStagedItem = createRenderStagedItem({ entityName: "Issue", numberField: "issue_number", ... });
const getSummaryLine = createGetSummaryLine({ entityPrefix: "Issue" });
async function main() {
  return await runUpdateWorkflow({
    itemType: "update_issue",
    displayName: "issue",
    numberField: "issue_number",
    ...,
    renderStagedItem,
    executeUpdate: executeIssueUpdate,
    getSummaryLine,
  });
}

(Same structure in update_pull_request.cjs with different strings/flags.)

Impact Analysis

  • Maintainability: Changes to staged preview formatting or workflow wiring must be updated in multiple files, inviting divergence.
  • Bug Risk: Inconsistent flags (supportsStatus, supportsOperation, output keys) could arise if one copy is updated without the other.
  • Code Bloat: Duplicated scaffolding obscures the truly different logic (update body handling vs. issue update) and inflates file size.

Refactoring Recommendations

  1. Introduce a shared factory (e.g., buildUpdateWorkflow(config)) or data-driven configuration map that registers entity-specific handlers (execute function, flags, labels) and reuses the common wrapper.
    • Estimated effort: 1-2h; benefits: single point for staged preview/render/summary wiring.
  2. Co-locate common render/summary configuration in update_runner.cjs (accepting entity descriptors) to avoid per-file boilerplate.

Implementation Checklist

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

Analysis Metadata

  • Analyzed Files: 2
  • 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