🔍 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
- 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.
- Co-locate common render/summary configuration in
update_runner.cjs (accepting entity descriptors) to avoid per-file boilerplate.
Implementation Checklist
Analysis Metadata
- Analyzed Files: 2
- Detection Method: Serena semantic code analysis
- Commit: a2389f6
- Analysis Date: 2025-01-06
AI generated by Duplicate Code Detector
🔍 Duplicate Code Detected: CJS update workflow scaffolding
Analysis of commit a2389f6
Assignee:
@copilotSummary
update_issue.cjsandupdate_pull_request.cjsboth reimplement the same workflow scaffolding—imports, staged preview renderer creation, summary line factory, and therunUpdateWorkflowinvocation 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
pkg/workflow/js/update_issue.cjs:4-58pkg/workflow/js/update_pull_request.cjs:4-94(Same structure in
update_pull_request.cjswith different strings/flags.)Impact Analysis
supportsStatus,supportsOperation, output keys) could arise if one copy is updated without the other.Refactoring Recommendations
buildUpdateWorkflow(config)) or data-driven configuration map that registers entity-specific handlers (execute function, flags, labels) and reuses the common wrapper.update_runner.cjs(accepting entity descriptors) to avoid per-file boilerplate.Implementation Checklist
Analysis Metadata