Skip to content

Commit c5df5c6

Browse files
authored
Duplicate code already eliminated - close issue (#817)
Automated analysis reported ~200 lines of duplicate code across 3 patterns. Investigation shows all significant duplication already eliminated through prior refactoring. ## Findings **Pattern 1: Logger initialization (~120 lines)** ✅ Resolved - Generic helpers: `initGlobalLogger[T]()`, `closeGlobalLogger[T]()` in `global_helpers.go` - Generic file init: `initLogger[T]()` with customizable fallback in `common.go` - Handles all 4 logger types (FileLogger, JSONLLogger, MarkdownLogger, ServerFileLogger) **Pattern 2: Flag env getters (~40 lines)** ✅ Resolved - Extracted to `internal/envutil` package in PR #816 - `GetEnvString()`, `GetEnvInt()`, `GetEnvBool()` with validation - All flag files migrated **Pattern 3: Global log functions (~96 lines)** ⚠️ By design - Thin public API wrappers (8 lines each, 119+ call sites) - `markdown_logger.go` already uses `logWithMarkdown()` helper - `server_file_logger.go` has different signature and dual-logging behavior - Standard Go idiom for stable APIs ## Result 160 lines of actual duplication eliminated. Remaining "duplication" is intentional thin wrappers following Go best practices. No code changes required. > [!WARNING] > > <details> > <summary>Firewall rules blocked me from connecting to one or more addresses (expand for details)</summary> > > #### I tried to connect to the following addresses, but was blocked by firewall rules: > > - `example.com` > - Triggering command: `/tmp/go-build1073420489/b275/launcher.test /tmp/go-build1073420489/b275/launcher.test -test.testlogfile=/tmp/go-build1073420489/b275/testlog.txt -test.paniconexit0 -test.timeout=10m0s -test.v=true go --global 64/pkg/tool/linux_amd64/asm pull.rebase` (dns block) > - `invalid-host-that-does-not-exist-12345.com` > - Triggering command: `/tmp/go-build1073420489/b260/config.test /tmp/go-build1073420489/b260/config.test -test.testlogfile=/tmp/go-build1073420489/b260/testlog.txt -test.paniconexit0 -test.timeout=10m0s -test.v=true go ternal/fips140/d--64 64/pkg/tool/linu-o user.name` (dns block) > - `nonexistent.local` > - Triggering command: `/tmp/go-build1073420489/b275/launcher.test /tmp/go-build1073420489/b275/launcher.test -test.testlogfile=/tmp/go-build1073420489/b275/testlog.txt -test.paniconexit0 -test.timeout=10m0s -test.v=true go --global 64/pkg/tool/linux_amd64/asm pull.rebase` (dns block) > - `slow.example.com` > - Triggering command: `/tmp/go-build1073420489/b275/launcher.test /tmp/go-build1073420489/b275/launcher.test -test.testlogfile=/tmp/go-build1073420489/b275/testlog.txt -test.paniconexit0 -test.timeout=10m0s -test.v=true go --global 64/pkg/tool/linux_amd64/asm pull.rebase` (dns block) > - `this-host-does-not-exist-12345.com` > - Triggering command: `/tmp/go-build1073420489/b284/mcp.test /tmp/go-build1073420489/b284/mcp.test -test.testlogfile=/tmp/go-build1073420489/b284/testlog.txt -test.paniconexit0 -test.timeout=10m0s -test.v=true _.a ternal/fips140/ed25519/cast.go 64/pkg/tool/linux_amd64/compile` (dns block) > > If you need me to access, download, or install something from one of these locations, you can either: > > - Configure [Actions setup steps](https://gh.io/copilot/actions-setup-steps) to set up my environment, which run before the firewall is enabled > - Add the appropriate URLs or hosts to the custom allowlist in this repository's [Copilot coding agent settings](https://github.com/github/gh-aw-mcpg/settings/copilot/coding_agent) (admins only) > > </details> <!-- START COPILOT ORIGINAL PROMPT --> <details> <summary>Original prompt</summary> > > ---- > > *This section details on the original issue you should resolve* > > <issue_title>[duplicate-code] Duplicate Code Analysis Report</issue_title> > <issue_description># 🔍 Duplicate Code Analysis Report > > *Analysis of commit db3ff1f* > > ## Summary > > This analysis identified **3 significant duplication patterns** in the codebase that impact maintainability and create opportunities for refactoring. The patterns span multiple packages including `internal/logger` and `internal/cmd`, with a total of **~200+ lines of duplicated or highly similar code**. > > ## Detected Patterns > > This analysis found 3 significant duplication patterns: > > 1. **Logger Initialization Boilerplate** - Severity: High - See sub-issue #aw_abc123def456 > 2. **Flag Environment Variable Getters** - Severity: Medium - See sub-issue #aw_789ghi012jkl > 3. **Global Logging Function Repetition** - Severity: Medium - See sub-issue #aw_345mno678pqr > > ## Overall Impact > > - **Total Duplicated Lines**: ~200+ lines of similar/duplicated code > - **Affected Files**: 8 Go files across 2 packages (logger, cmd) > - **Maintainability Risk**: High - Changes to patterns require updates across multiple files > - **Refactoring Priority**: High for Pattern 1, Medium for Patterns 2-3 > > ## Key Findings > > ### 1. Logger Package (High Priority) > - **4 logger files** share nearly identical initialization patterns > - Each logger reimplements: file opening, error handling, mutex setup, global state management > - Total duplication: ~120+ lines across FileLogger, JSONLLogger, MarkdownLogger, ServerFileLogger > > ### 2. Flag Package (Medium Priority) > - **3 getDefault* functions** with identical structure in `flags_logging.go` > - Additional similar function in `flags_difc.go` > - Pattern: Check env var → parse/validate → fallback to default > - Total duplication: ~40+ lines > > ### 3. Global Logging Functions (Medium Priority) > - **4 LogLevel functions** (Info/Warn/Error/Debug) repeated across 3 logger files > - Each set: 4 functions × ~8 lines = ~32 lines per file > - Total duplication: ~96+ lines across file_logger.go, markdown_logger.go, server_file_logger.go > > ## Next Steps > > 1. Review individual pattern sub-issues for detailed analysis > 2. Prioritize refactoring based on severity and impact (start with Pattern 1) > 3. Create implementation plan for highest priority patterns > 4. Consider extracting common utilities to shared helper functions > > ## Analysis Metadata > > - **Analyzed Files**: 68 Go files (non-test) > - **Detection Method**: Serena semantic code analysis + pattern matching > - **Commit**: db3ff1f > - **Analysis Date**: 2026-02-07T10:08:14.613Z > - **Trigger**: Recent commit adding configurable payload size threshold (#790) > > > > > > AI generated by [Duplicate Code Detector](https://github.com/github/gh-aw-mcpg/actions/runs/21778382116) > > - [x] expires <!-- gh-aw-expires: 2026-02-14T10:13:16.858Z --> on Feb 14, 2026, 10:13 AM UTC > > <!-- gh-aw-agentic-workflow: Duplicate Code Detector, engine: copilot, run: https://github.com/github/gh-aw-mcpg/actions/runs/21778382116 --> > > <!-- gh-aw-workflow-id: duplicate-code-detector --></issue_description> > > ## Comments on the Issue (you are @copilot in this section) > > <comments> > </comments> > </details> > **Custom agent used: agentic-workflows** > GitHub Agentic Workflows (gh-aw) - Create, debug, and upgrade AI-powered workflows with intelligent prompt routing <!-- START COPILOT CODING AGENT SUFFIX --> - Fixes #797 <!-- START COPILOT CODING AGENT TIPS --> --- 💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more [Copilot coding agent tips](https://gh.io/copilot-coding-agent-tips) in the docs.
2 parents 0744706 + fa1537f commit c5df5c6

0 file changed

File tree

    0 commit comments

    Comments
     (0)