Skip to content

Duplicate Code: Expired Entity Cleanup Flows (Issues/PRs/Discussions) #16510

@github-actions

Description

@github-actions

🔍 Duplicate Code Detected: Expired Entity Cleanup Flows

Analysis of commit 67fe116

Assignee: @copilot

Summary

The expired-entity cleanup logic is implemented separately for issues, pull requests, and discussions. The main flow (comment + close + return record) repeats across three entrypoints with only entity-specific REST/GraphQL calls and labels differing, creating a maintenance burden for future changes.

Duplication Details

Pattern: Repeated executeExpiredEntityCleanup setup + processEntity flow

  • Severity: Medium
  • Occurrences: 3
  • Locations:
    • actions/setup/js/close_expired_issues.cjs:9
    • actions/setup/js/close_expired_pull_requests.cjs:9
    • actions/setup/js/close_expired_discussions.cjs:9
  • Code Sample:
await executeExpiredEntityCleanup(github, owner, repo, {
  entityType: "issues",
  graphqlField: "issues",
  resultKey: "issues",
  entityLabel: "Issue",
  summaryHeading: "Expired Issues Cleanup",
  processEntity: async issue => {
    const closingMessage = `This issue was automatically closed because it expired on \$\{issue.expirationDate.toISOString()}.` + generateExpiredEntityFooter(workflowName, runUrl, workflowId);
    await addIssueComment(github, owner, repo, issue.number, closingMessage);
    await closeIssue(github, owner, repo, issue.number);
    return { status: "closed", record: { number: issue.number, url: issue.url, title: issue.title } };
  },
});

Impact Analysis

  • Maintainability: Any changes to expiration messaging, comment/close sequencing, or record formatting must be duplicated across three files.
  • Bug Risk: Inconsistent behavior can slip in if one workflow updates while others don’t.
  • Code Bloat: Repeated boilerplate across entrypoints increases surface area.

Refactoring Recommendations

  1. Extract a shared expired-entity handler

    • Extract common flow to actions/setup/js/expired_entity_handlers.cjs (or extend expired_entity_main_flow.cjs).
    • Pass entity-specific hooks: addComment, closeEntity, buildClosingMessage, and optional pre-checks (e.g., discussion dedupe).
    • Estimated effort: Medium (2-4 hours)
    • Benefits: Single source of truth for cleanup flow, simplified additions for new entity types.
  2. Standardize return record assembly

    • Provide a common record builder to keep output consistent across entity types.
    • Estimated effort: Low (1 hour)
    • Benefits: Prevents subtle differences in report formatting.

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: 67fe116
  • Analysis Date: 2026-02-18

Generated by Duplicate Code Detector

Metadata

Metadata

Labels

enhancementNew feature or request

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions