🔍 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
-
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.
-
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
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
🔍 Duplicate Code Detected: Network Access vs Firewall Summaries
Analysis of commit 837cf5f
Assignee:
@copilotSummary
buildAccessLogSummaryandbuildFirewallLogSummaryinpkg/cli/logs_report.goboth accumulate domain-level statistics fromprocessedRuns; the control flow is the same and differs only in the extraRequestsByDomainmap maintained for firewall data.Duplication Details
Pattern: Parallel domain aggregation for access and firewall logs
pkg/cli/logs_report.go:371pkg/cli/logs_report.go:423Impact Analysis
Refactoring Recommendations
Shared domain aggregation helper
Composable options pattern
RequestsByDomain) while reusing the traversal.Implementation Checklist
Analysis Metadata