Skip to content

Duplicate Code: expired-entity cleanup main flow in JS actionsΒ #14291

@github-actions

Description

@github-actions

πŸ” Duplicate Code Detected: Expired entity cleanup flow (issues/PRs/discussions)

Analysis of commit 080dad7

Assignee: @copilot

Summary

The main workflow for expiring entities (search β†’ categorize β†’ summary β†’ close) is implemented three times with nearly identical control flow in the expired discussions/issues/PR scripts. The differences are limited to entity labels and the specific close/comment helpers, so this is a good candidate for shared orchestration to reduce maintenance drift.

Duplication Details

Pattern: Expired entity cleanup main flow

  • Severity: Medium
  • Occurrences: 3
  • Locations:
    • actions/setup/js/close_expired_discussions.cjs (lines 89-216)
    • actions/setup/js/close_expired_issues.cjs (lines 46-136)
    • actions/setup/js/close_expired_pull_requests.cjs (lines 45-135)
  • Code Sample:
// Shared structure across all three files
core.info(`Searching for expired … in ${owner}/${repo}`);
const { items, stats } = await searchEntitiesWithExpiration(...);
if (items.length === 0) { /* write summary; return */ }
const { expired, notExpired, now } = categorizeByExpiration(items, ...);
if (expired.length === 0) { /* write summary; return */ }
const { closed, failed } = await processExpiredEntities(expired, { processEntity: async entity => { /* comment + close */ } });
const summaryContent = buildExpirationSummary({ ... });
await core.summary.addRaw(summaryContent).write();

Impact Analysis

  • Maintainability: Changes to summary format, logging, or error handling must be repeated across three files.
  • Bug Risk: Inconsistent fixes are likely (e.g., one entity type gets improved handling and others do not).
  • Code Bloat: ~250+ duplicated lines across three files.

Refactoring Recommendations

  1. Extract a shared orchestration helper

    • Extract to: actions/setup/js/expired_entity_cleanup_helpers.cjs (or a new expired_entity_main_flow.cjs)
    • Estimated effort: 2-4 hours
    • Benefits: Single place to update summary and flow control
  2. Parameterize entity-specific behavior

    • Pass in labels, result keys, and the processEntity implementation
    • Keeps entity-specific API calls local while sharing the flow

Implementation Checklist

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

Analysis Metadata

  • Analyzed Files: 3
  • Detection Method: Serena semantic code analysis
  • Commit: 080dad7
  • Analysis Date: 2026-02-07

AI generated by Duplicate Code Detector

Metadata

Metadata

Labels

No labels
No labels

Type

No type
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