-
Notifications
You must be signed in to change notification settings - Fork 46
Closed
Description
Analysis of commit b2f8b8a
Assignee: @copilot
Summary
The expired-entity cleanup scripts for issues, pull requests, and discussions contain large, near-identical logic for expiration evaluation, per-item processing, delay handling, and summary generation. This duplication exceeds 10 lines and appears in 3+ files, making future changes error-prone and difficult to keep consistent.
Duplication Details
Pattern: Expiration evaluation + close loop + summary rendering
- Severity: Medium
- Occurrences: 3
- Locations:
actions/setup/js/close_expired_issues.cjs(lines 120-279)actions/setup/js/close_expired_pull_requests.cjs(lines 120-279)actions/setup/js/close_expired_discussions.cjs(lines 164-340)
- Code Sample:
// Check if expired
const isExpired = now >= expirationDate;
const timeDiff = expirationDate.getTime() - now.getTime();
const daysUntilExpiration = Math.floor(timeDiff / (1000 * 60 * 60 * 24));
const hoursUntilExpiration = Math.floor(timeDiff / (1000 * 60 * 60));
if (isExpired) {
const daysSinceExpiration = Math.abs(daysUntilExpiration);
const hoursSinceExpiration = Math.abs(hoursUntilExpiration);
core.info(` ✓ ... is EXPIRED (expired ${daysSinceExpiration} days, ${hoursSinceExpiration % 24} hours ago)`);
expiredItems.push({ ...item, expirationDate });
} else {
core.info(` ✗ ... is NOT expired (expires in ${daysUntilExpiration} days, ${hoursUntilExpiration % 24} hours)`);
notExpiredItems.push({ ...item, expirationDate });
}Impact Analysis
- Maintainability: Changes to expiration logic or summary formatting must be duplicated across three files, increasing drift risk.
- Bug Risk: Fixes in one script can easily be missed in the others (e.g., edge cases around expiration parsing or summary formatting).
- Code Bloat: The duplicated sections are large (loop + summary builder), increasing file size and review cost.
Refactoring Recommendations
-
Extract shared expiration processing utility
- Extract to:
actions/setup/js/expiration_helpers.cjsor a newexpired_entity_cleanup_helpers.cjs - Estimated effort: Medium (2-4 hours)
- Benefits: Single source of truth for expiration calculations, logging, and summary rendering
- Extract to:
-
Create a shared “cleanup runner” helper
- Extract the common loop for: selecting items, processing with delay, and summary building
- Estimated effort: Medium
- Benefits: Reduces drift and eases adding new entity types in future
Implementation Checklist
- Review duplication findings
- Prioritize refactoring tasks
- Create refactoring plan
- Implement shared helpers
- Update tests
- Verify no functionality broken
Analysis Metadata
- Analyzed Files: 3
- Detection Method: Serena semantic code analysis
- Commit: b2f8b8a
- Analysis Date: 2026-02-03 05:49:16 UTC
AI generated by Duplicate Code Detector
Codex