-
Notifications
You must be signed in to change notification settings - Fork 307
Closed
Closed
Copy link
Description
🔍 Duplicate Code Detected: Expires preprocessing in create-issue/create-discussion
Analysis of commit c4416a7
Assignee: @copilot
Summary
The expires preprocessing block in parseIssuesConfig and parseDiscussionsConfig is effectively identical (parses expires, handles false disablement, normalizes to hours, logs). This is >10 lines duplicated in two core config parsers.
Duplication Details
Pattern: Expires normalization and disablement parsing
- Severity: Medium
- Occurrences: 2
- Locations:
pkg/workflow/create_issue.go:37pkg/workflow/create_discussion.go:40
- Code Sample:
// Pre-process the expires field (convert to hours before unmarshaling)
expiresDisabled := false
if configData != nil {
if expires, exists := configData["expires"]; exists {
expiresInt := parseExpiresFromConfig(configData)
if expiresInt == -1 { ... } else if expiresInt > 0 { ... } else { ... }
log.Printf("Parsed expires value %v to %d hours (disabled=%t)", expires, expiresInt, expiresDisabled)
}
}Impact Analysis
- Maintainability: Changes to expires parsing logic must be made in two places, risking drift.
- Bug Risk: If one parser is updated and the other is not, behavior diverges between issue and discussion workflows.
- Code Bloat: Small but repeated block in a core config path.
Refactoring Recommendations
-
Extract a shared helper
- Extract to:
pkg/workflow/expiration_helpers.go(or similar) and return(expires int, disabled bool). - Estimated effort: ~1–2 hours.
- Benefits: Single source of truth for expires parsing and logging.
- Extract to:
-
Standardize logging
- Accept a logger in the helper to keep caller-specific prefixing consistent.
- Estimated effort: ~0.5 hour.
- Benefits: Consistent logging format and fewer call sites to update.
Implementation Checklist
- Review duplication findings
- Prioritize refactoring tasks
- Create refactoring plan
- Implement changes
- Update tests
- Verify no functionality broken
Analysis Metadata
- Analyzed Files: 6 (create/update issue/discussion/pull_request)
- Detection Method: Serena semantic code analysis + pattern matching
- Commit: c4416a7
- Analysis Date: February 11, 2026
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.