Skip to content

[duplicate-code] Duplicate Code: closeOlder issue/PR adapter wrappers share the same wiring #45043

Description

@github-actions

🔍 Duplicate Code Detected: closeOlder Adapter Wrappers

Analysis of commit bc7d2db

Summary

The closeOlderIssues and closeOlderPullRequests wrappers are structurally the same: they pass the same config shape into closeOlderEntities, differ only in entity names and callback targets, and return the same mapped result shape. This is a copy-paste adapter pattern that can be parameterized.

Duplication Details

Pattern: closeOlder adapter wiring

  • Severity: Medium
  • Occurrences: 2
  • Locations:
    • actions/setup/js/close_older_issues.cjs (lines 188-214)
    • actions/setup/js/close_older_pull_requests.cjs (lines 187-213)
  • Code Sample:
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),
  getCloseMessage: params => getCloseOlderIssueMessage({ ... }),
  addComment: addIssueComment,
  closeEntity: closeIssueAsNotPlanned,
  delayMs: API_DELAY_MS,
  getEntityId: entity => entity.number,
  getEntityUrl: entity => entity.html_url,
});

Impact Analysis

  • Maintainability: Any change to the adapter contract has to be repeated in both files.
  • Bug Risk: Small mismatches between the two wrappers can diverge behavior for issues vs. PRs.
  • Code Bloat: The wrappers are mostly repeated configuration data with different names.

Refactoring Recommendations

  1. Extract a typed wrapper factory

    • Extract common logic to: actions/setup/js/close_older_entity_factory.cjs
    • Estimated effort: small
    • Benefits: one shared adapter path for entity naming, message construction, and close callbacks
  2. Pass entity-specific config objects

    • Replace per-file wiring with a config object for entity label, message builder, search function, and close handler
    • Estimated effort: small to medium
    • Benefits: less duplication and simpler future entity additions

Implementation Checklist

  • Review duplication findings
  • Prioritize refactoring tasks
  • Create refactoring plan
  • Implement changes
  • Update tests
  • Verify no functionality broken

Analysis Metadata

  • Analyzed Files: 5
  • Detection Method: Serena semantic code analysis
  • Commit: bc7d2db
  • Analysis Date: 2026-07-12

Warning

Firewall blocked 1 domain

The following domain was blocked by the firewall during workflow execution:

  • awmgmcpg

To allow these domains, add them to the network.allowed list in your workflow frontmatter:

network:
  allowed:
    - defaults
    - "awmgmcpg"

See Network Configuration for more information.

Generated by 🔍 Duplicate Code Detector · 14.7 AIC · ⌖ 1.17 AIC · ⊞ 11.5K ·

  • expires on Jul 13, 2026, 10:19 PM UTC-08:00

Metadata

Metadata

Type

No type

Fields

No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions