Skip to content

[duplicate-code] 馃攳 Duplicate Code Detected: Logs Report Tool Failure Summaries#3584

Description

@github-actions

馃攳 Duplicate Code Detected: Logs Report Tool Failure Summaries

Analysis of commit 837cf5f

Assignee: @copilot

Summary

The helper functions buildMissingToolsSummary and buildMCPFailuresSummary in pkg/cli/logs_report.go share the same aggregation flow when turning processedRuns into summary structs, differing only by target type and field names.

Duplication Details

Pattern: Duplicate aggregation for missing tools vs. MCP failures

  • Severity: Medium
  • Occurrences: 2
  • Locations:
    • pkg/cli/logs_report.go:295
    • pkg/cli/logs_report.go:334
  • Code Sample:
    summaryMap := make(map[string]*T)
    
    for _, pr := range processedRuns {
        for _, item := range sourceSlice(pr) {
            if summary, exists := summaryMap[item.Key]; exists {
                summary.Count++
                summary.Workflows = addUniqueWorkflow(summary.Workflows, item.WorkflowName)
                summary.RunIDs = append(summary.RunIDs, item.RunID)
            } else {
                summaryMap[item.Key] = &T{
                    Key:       item.Key,
                    Count:     1,
                    Workflows: []string{item.WorkflowName},
                    RunIDs:    []int64{item.RunID},
                }
            }
        }
    }

Impact Analysis

  • Maintainability: Any display change (e.g., new fields or sorting tweaks) must be applied twice.
  • Bug Risk: Diverging defaults or forgetting to update one branch can lead to inconsistent CLI output.
  • Code Bloat: ~35 lines repeated back-to-back obscure the differences between summaries.

Refactoring Recommendations

  1. Generic summarizer helper

    • Introduce a parameterized helper that takes key selectors and constructors for the summary struct.
    • Estimated effort: Medium (~2 hours)
    • Benefits: Consolidates repeated loops, makes future summary types easier to add.
  2. Leverage typed adapters

    • Define small adapter interfaces (e.g., logSummaryItem) so both cases can share the aggregation pipeline while providing type-specific assignments.
    • Estimated effort: Medium
    • Benefits: Makes intent clearer and removes map boilerplate duplication.

Implementation Checklist

  • Review duplication findings
  • Prioritize refactoring tasks
  • Create refactoring plan
  • Implement changes
  • Update tests
  • Verify no functionality broken

Analysis Metadata

  • Analyzed Files: 1
  • Detection Method: Serena semantic code analysis
  • Commit: 837cf5f
  • Analysis Date: 2025-11-11T02:21:46Z

AI generated by Duplicate Code Detector

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions