Skip to content

[duplicate-code] Duplicate Code: close-handler REST wrappers repeated across entity flows #51646

Description

@github-actions

🔍 Duplicate Code Detected: Close-Handler REST Wrapper Functions

Analysis of commit 2b4a6df88d5ea6216b577a0af184f9cecff96771

Assignee: @copilot

Duplicate close-handler report - 2026-08-09

Summary

The close-handler modules already use createCloseEntityHandler, but they still duplicate thin REST wrappers for get*Details, add*Comment, and close* operations across both primary close handlers and close_older_* flows. The repeated wrappers are structurally identical and differ mainly in endpoint names and log strings.

Duplication Details

Pattern: repeated REST wrapper helpers for issue and pull request close flows

  • Severity: Medium
  • Occurrences: 4+ similar blocks
  • Locations:
    • actions/setup/js/close_issue.cjs (lines 118-188)
    • actions/setup/js/close_pull_request.cjs (lines 21-66)
    • actions/setup/js/close_older_issues.cjs (lines 80-125)
    • actions/setup/js/close_older_pull_requests.cjs (lines 77-121)
  • Code Sample:
async function addPullRequestComment(github, owner, repo, prNumber, message) {
  const { data: comment } = await github.rest.issues.createComment({
    owner,
    repo,
    issue_number: prNumber,
    body: message,
  });
  return comment;
}

async function closePullRequest(github, owner, repo, prNumber) {
  const { data: pr } = await github.rest.pulls.update({
    owner,
    repo,
    pull_number: prNumber,
    state: "closed",
  });
  return pr;
}

Impact Analysis

  • Maintainability: every logging or error-handling change to close wrappers has to be copied into multiple files.
  • Bug Risk: sanitization and response-shape behavior already diverge between the primary close handlers and the close_older_* variants.
  • Code Bloat: the transport code competes with the actual business rules for close policies.

Refactoring Recommendations

  1. Extract shared REST close helpers for issue and pull request flows

    • Provide common helpers for getDetails, addComment, and close operations, with options for state reason and logging.
    • Estimated effort: 2-4 hours
    • Benefits: one implementation for response handling and sanitization.
  2. Make close_older_* reuse the same transport helpers

    • Keep only the policy-specific behavior in the close_older_* modules and delegate API operations to shared helpers.
    • Estimated effort: 1-2 hours
    • Benefits: fewer drift points between normal close flows and cleanup flows.

Implementation Checklist

  • Identify which close wrapper behaviors are truly entity-specific
  • Extract shared REST helpers for issue and pull request access/comment/close operations
  • Reuse them from both primary close handlers and close_older_* modules
  • Verify sanitization and logging behavior remain intentional after consolidation
  • Re-run close-handler tests for issue and pull request scenarios

Analysis Metadata

  • Analyzed Files: targeted review of 14 files within 1,599 eligible changed .go/.cjs paths in the shallow initial-import snapshot
  • Detection Method: Serena-guided analysis and targeted source inspection
  • Commit: 2b4a6df88d5ea6216b577a0af184f9cecff96771
  • Analysis Date: 2026-08-09T22:01:37Z

Generated by 🔍 Duplicate Code Detector · gpt54 · 103.8 AIC · ⊞ 12.8K ·

  • expires on Aug 11, 2026, 2:04 PM UTC-08:00

Metadata

Metadata

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions