Overview
A significant near-duplicate implementation exists between the safe-output handlers for closing issues and closing pull requests.
The duplicated flow includes configuration parsing, max-count gating, comment-body resolution, staged-mode preview handling, label/title filtering, close execution, and verbose error/log handling.
Critical Findings
- Pattern: Near-identical close-flow pipeline implemented in separate modules
- Severity: Medium
- Occurrences: 2 primary handlers, plus overlapping utility logic duplicated against an existing helper module
- Threshold Check: Exceeds >10 duplicated lines by a wide margin (roughly 100+ structurally similar lines)
Duplication Details
The two handlers implement highly similar end-to-end logic in their main() returned handler functions:
- Parse/validate target number
- Resolve comment text fallback and sanitize
- Apply required labels/title-prefix filters
- Handle staged mode preview
- Post comment
- Close target entity
- Return structured success/failure payload
Additionally, helper logic like buildCommentBody, label filtering, and title-prefix filtering is duplicated in close_pull_request.cjs:318 and already exists in close_entity_helpers.cjs:47.
Code Evidence (high-level)
close_issue.cjs main processing pipeline: lines 84-301
close_pull_request.cjs main processing pipeline: lines 85-310
- Existing generalized helper pipeline (
processCloseEntityItems): lines 214-383 in close_entity_helpers.cjs
Impact Analysis
- Maintainability: Bug fixes and behavior changes must be repeated across handlers, increasing drift risk.
- Bug Risk: Inconsistent behavior can emerge over time (e.g., error handling and comment/footer behavior).
- Code Bloat: Existing abstraction (
close_entity_helpers.cjs) is underused while duplicate handler logic continues to grow.
Recommendations
- Migrate
close_issue.cjs and close_pull_request.cjs to a shared entity-close runner in close_entity_helpers.cjs.
- Keep only entity-specific callbacks in each handler (
getDetails, addComment, closeEntity) and centralize common flow.
- Reuse shared helper functions for comment-body construction and filters; remove duplicated local implementations.
Implementation Checklist
Analysis Metadata
- Commit:
68515c18ed1602fb1eb44e24e35718e93c6c8eb8
- Detection Method: Serena symbol analysis + structural diff inspection
- Eligible changed files: 931 (
.go/.cjs, excluding test/workflow patterns)
- Workflow Run: §24241739247
Generated by Duplicate Code Detector · ◷
Overview
A significant near-duplicate implementation exists between the safe-output handlers for closing issues and closing pull requests.
The duplicated flow includes configuration parsing, max-count gating, comment-body resolution, staged-mode preview handling, label/title filtering, close execution, and verbose error/log handling.
Critical Findings
Duplication Details
The two handlers implement highly similar end-to-end logic in their
main()returned handler functions:Additionally, helper logic like
buildCommentBody, label filtering, and title-prefix filtering is duplicated in close_pull_request.cjs:318 and already exists in close_entity_helpers.cjs:47.Code Evidence (high-level)
close_issue.cjsmain processing pipeline: lines 84-301close_pull_request.cjsmain processing pipeline: lines 85-310processCloseEntityItems): lines 214-383 inclose_entity_helpers.cjsImpact Analysis
close_entity_helpers.cjs) is underused while duplicate handler logic continues to grow.Recommendations
close_issue.cjsandclose_pull_request.cjsto a shared entity-close runner inclose_entity_helpers.cjs.getDetails,addComment,closeEntity) and centralize common flow.Implementation Checklist
close_entity_helpers.cjsclose_pull_request.cjsto consume shared flowclose_issue.cjsto consume shared flow (including cross-repo handling where needed)Analysis Metadata
68515c18ed1602fb1eb44e24e35718e93c6c8eb8.go/.cjs, excluding test/workflow patterns)