Skip to content

[duplicate-code] 🔍 Duplicate Code Detected: Network Access vs Firewall Summaries #3585

Description

@github-actions

🔍 Duplicate Code Detected: Network Access vs Firewall Summaries

Analysis of commit 837cf5f

Assignee: @copilot

Summary

buildAccessLogSummary and buildFirewallLogSummary in pkg/cli/logs_report.go both accumulate domain-level statistics from processedRuns; the control flow is the same and differs only in the extra RequestsByDomain map maintained for firewall data.

Duplication Details

Pattern: Parallel domain aggregation for access and firewall logs

  • Severity: Medium
  • Occurrences: 2
  • Locations:
    • pkg/cli/logs_report.go:371
    • pkg/cli/logs_report.go:423
  • Code Sample:
    allAllowedDomains := make(map[string]bool)
    allDeniedDomains := make(map[string]bool)
    byWorkflow := make(map[string]*Analysis)
    totals := counts{}
    
    for _, pr := range processedRuns {
        analysis := extractAnalysis(pr)
        if analysis == nil {
            continue
        }
        totals.add(analysis)
        byWorkflow[pr.Run.WorkflowName] = analysis
    
        for _, domain := range analysis.AllowedDomains {
            allAllowedDomains[domain] = true
        }
        for _, domain := range analysis.DeniedDomains {
            allDeniedDomains[domain] = true
        }
    }

Impact Analysis

  • Maintainability: Updates to domain aggregation logic (e.g., deduping or sorting changes) require synchronized edits in two places.
  • Bug Risk: Future enhancements may be applied to one summary but not the other, leading to inconsistent CLI reports.
  • Code Bloat: ~45 similar lines increase cognitive load when understanding the logging pipeline.

Refactoring Recommendations

  1. Shared domain aggregation helper

    • Extract a function that accepts accessors for allowed/denied domains and per-run metrics, returning a struct consumed by both summaries.
    • Estimated effort: Medium (~2 hours)
    • Benefits: Centralizes domain handling and simplifies future extensions.
  2. Composable options pattern

    • Use functional options or small callback interfaces to plug in firewall-specific counters (e.g., RequestsByDomain) while reusing the traversal.
    • Estimated effort: Medium
    • Benefits: Keeps special cases explicit without duplicating the traversal code.

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

Metadata

Metadata

Assignees

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