Skip to content

[duplicate-code] Duplicate Code: close_older handlers repeated across issues, pull requests, and discussions #53500

Description

@github-actions

🔍 Duplicate Code Detected: close_older entity handlers

Analysis of commit f4f83c21101e6037c9b64af5c05c4771eace751c

Assignee: @copilot

Summary

The close_older_* handlers for issues, pull requests, and discussions duplicate the same orchestration shape: marker search, comment creation, entity closure, closing-message rendering, and the final closeOlderEntities(...) adapter. The differences are mostly API surface details and a few entity-specific field names.

Duplication Details

Pattern: parallel close-older handlers by entity type

  • Severity: Medium
  • Occurrences: 3
  • Locations:
    • actions/setup/js/close_older_issues.cjs (lines 18-190)
    • actions/setup/js/close_older_pull_requests.cjs (lines 18-183)
    • actions/setup/js/close_older_discussions.cjs (lines 20-191)
  • Code Sample:
async function closeOlderIssues(...) {
  const result = await closeOlderEntities(github, owner, repo, workflowId, newIssue, workflowName, runUrl, {
    entityType: "issue",
    entityTypePlural: "issues",
    searchOlderEntities: (gh, o, r, wid, excludeNumber) =>
      searchOlderIssues(gh, o, r, wid, excludeNumber, callerWorkflowId, closeOlderKey, currentRunIssueNumbers),
    getCloseMessage: params => getCloseOlderIssueMessage({ ... }),
    addComment: addIssueComment,
    closeEntity: closeIssueAsNotPlanned,
    delayMs: API_DELAY_MS,
    getEntityId: entity => entity.number,
    getEntityUrl: entity => entity.html_url,
  });
  return result.map(item => ({ number: item.number, html_url: item.html_url || "" }));
}

The pull-request and discussion variants repeat the same structure with entity-specific names and transport details. The duplication also extends into the per-entity search helpers and comment/close functions in the same files.

Impact Analysis

  • Maintainability: Every behavioral change to close-older matching, logging, or result mapping has to be applied in three places.
  • Bug Risk: The issue variant already has an extra currentRunIssueNumbers exclusion path that the other handlers do not share, which increases the chance of behavior drifting silently between entity types.
  • Code Bloat: Roughly 170-180 lines per file are mostly scaffold around the same underlying algorithm.

Refactoring Recommendations

  1. Extract an entity descriptor-driven factory

    • Extract common functionality to: actions/setup/js/close_older_handler_factory.cjs
    • Estimated effort: 4-6 hours
    • Benefits: consolidates the repeated closeOlderEntities(...) wiring and local wrapper functions into a single descriptor table.
  2. Split transport-specific primitives from entity semantics

    • Extract common functionality to: actions/setup/js/close_older_entity_adapters.cjs
    • Estimated effort: 2-4 hours
    • Benefits: keeps REST vs GraphQL differences isolated while eliminating duplicated search/comment/close scaffolding.

Implementation Checklist

  • Review duplication findings
  • Prioritize refactoring tasks
  • Create refactoring plan
  • Implement changes
  • Update tests
  • Verify no functionality broken
Analysis Metadata
  • Analyzed Files: 7 source files in the recent source-bearing area, plus supporting comparison files
  • Detection Method: Shell-based structural comparison after Serena Go analysis was unavailable (go missing in the environment)
  • Commit: f4f83c21101e6037c9b64af5c05c4771eace751c
  • Analysis Date: 2026-08-17T21:58:33Z
  • Note: The head commit only changed workflow YAML, so source review fell back to the most recent source-bearing commits and surrounding code paths.

Generated by 🔍 Duplicate Code Detector · gpt54 · 111.1 AIC · ⊞ 13.1K ·

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

Activity

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

Metadata

Metadata

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions