-
Notifications
You must be signed in to change notification settings - Fork 301
Closed
Description
π 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
-
Extract a shared orchestration helper
- Extract to:
actions/setup/js/expired_entity_cleanup_helpers.cjs(or a newexpired_entity_main_flow.cjs) - Estimated effort: 2-4 hours
- Benefits: Single place to update summary and flow control
- Extract to:
-
Parameterize entity-specific behavior
- Pass in labels, result keys, and the
processEntityimplementation - Keeps entity-specific API calls local while sharing the flow
- Pass in labels, result keys, and the
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
Reactions are currently unavailable
Metadata
Metadata
Labels
No labels
Type
Fields
Give feedbackNo fields configured for issues without a type.