Skip to content

Duplicate Code: Expires Preprocessing in create-issue and create-discussion #14898

@github-actions

Description

@github-actions

🔍 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:37
    • pkg/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

  1. 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.
  2. 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

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