-
Notifications
You must be signed in to change notification settings - Fork 31
Closed as not planned
Closed as not planned
Copy link
Description
🔍 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-100pkg/workflow/js/update_pull_request.cjs:6-150
- Code Sample:
The
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, }); }
update_pull_requestversion is the same block with only label names andsupportsOperationtoggled. 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
- 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.
- Instead of duplicating wrapper files, export metadata objects (labels, field support, REST handler) and feed them into a shared factory (e.g.,
- Share context helpers
- Move
isIssueContext/isPRContext+ number extraction intoupdate_runner.cjsor acontext_detectors.cjsmodule so other update types can reuse them without new copies. - Estimated effort: 2 hours.
- Move
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/.cjsfiles (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
Copilot