Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Dec 19, 2025

Refactor Duplicate Update Workflow Scaffolding

Analysis Complete

  • Analyzed update_issue.cjs and update_pull_request.cjs
  • Reviewed update_runner.cjs (already has shared helpers)
  • Examined test files to understand testing approach
  • Reviewed project structure and build system

Implementation Plan

  • Create buildUpdateWorkflow factory function in update_runner.cjs
  • Refactor update_issue.cjs to use the new factory
  • Refactor update_pull_request.cjs to use the new factory
  • Run JavaScript tests to ensure no functionality broken
  • Run make lint-cjs to validate code formatting
  • Verify no regression with integration tests

Approach

Instead of creating a new file, will extend the existing update_runner.cjs module with a factory function that accepts a configuration object and returns a ready-to-run main function. This will:

  • Eliminate duplicate scaffolding in both files
  • Maintain existing functionality and API
  • Keep entity-specific logic (like executeIssueUpdate and executePRUpdate) in their respective files
  • Reduce code from ~60 lines to ~15 lines per file
Original prompt

This section details on the original issue you should resolve

<issue_title>[duplicate-code] CJS update workflows duplicate runUpdateWorkflow scaffolding for issue and PR</issue_title>
<issue_description># 🔍 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

Comments on the Issue (you are @copilot in this section)


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

3 participants