Skip to content

[duplicate-code] Duplicate Code: Older-Entity Search Flow in Close Helpers #47868

Description

@github-actions

🔍 Duplicate Code Detected: Older-Entity Search Flow

Analysis of commit 44b56e1

Summary

The searchOlder* helpers for issues, pull requests, and discussions reimplement the same search/filter/mapping pipeline with only small entity-specific differences. The shared helper layer covers some of the closing logic, but the search entrypoints still carry a large duplicated block that could be parameterized further.

Duplication Details

Pattern: Search-and-filter pipeline for older entities

  • Severity: Medium
  • Occurrences: 3
  • Locations:
    • actions/setup/js/close_older_issues.cjs (lines 35-99)
    • actions/setup/js/close_older_pull_requests.cjs (lines 33-96)
    • actions/setup/js/close_older_discussions.cjs (lines 36-119)
  • Code Sample:
core.info(`Starting search for older ...`);
if (!workflowId && !closeOlderKey) return [];
const { searchQuery, exactMarker } = buildMarkerSearchQuery(...);
const result = await github....search(...);
if (!result || !...) return [];
const { filtered } = filterByMarker({ ... });
return filtered.map(item => (...));

Impact Analysis

  • Maintainability: search behavior now has three near-parallel implementations, so fixes to query construction, logging, or filtering logic need to be repeated.
  • Bug Risk: entity-specific patches can drift between issues, PRs, and discussions, especially around search qualifiers and exclusion logic.
  • Code Bloat: the repeated pipeline is substantial enough to justify a shared helper or higher-order adapter.

Refactoring Recommendations

  1. Extract a generic older-entity search helper

    • Centralize query execution, empty-result handling, filtering, and mapping in one helper under actions/setup/js/close_older_entities.cjs or a new sibling module.
    • Estimated effort: medium
    • Benefits: one place to update search semantics and logging.
  2. Pass entity-specific adapters/callbacks

    • Keep only the GraphQL vs REST call, entity label, and extra filters in the per-entity files.
    • Estimated effort: medium
    • Benefits: reduces the surface area for drift without changing behavior.

Implementation Checklist

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

Analysis Metadata

  • Analyzed Files: 3 changed non-test .cjs files in this pattern
  • Detection Method: Serena semantic code analysis
  • Commit: 44b56e1
  • Analysis Date: 2026-07-24

Generated by 🔍 Duplicate Code Detector · gpt54 · 17.8 AIC · ⌖ 2.65 AIC · ⊞ 11.1K ·

  • expires on Jul 26, 2026, 2:15 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