Skip to content

[duplicate-code] Duplicate Code: GitHub MCP Rendering Logic in Engine Implementations #2321

@github-actions

Description

@github-actions

🔍 Duplicate Code Detected: GitHub MCP Renderer Logic

Analysis of commit 7658c86

Assignee: @copilot

Summary

Rendering the GitHub MCP server configuration is implemented separately in the Copilot, Claude, Codex, and Custom engine files. Each version repeats the same remote/local branching, token precedence, and closing boilerplate with only minor option differences.

Duplication Details

Pattern: Repeated GitHub MCP rendering branches in engine renderers

  • Severity: Medium
  • Occurrences: 4
  • Locations:
    • pkg/workflow/copilot_engine.go:398
    • pkg/workflow/claude_engine.go:652
    • pkg/workflow/codex_engine.go:479
    • pkg/workflow/custom_engine.go:161
  • Code Sample:
    githubType := getGitHubType(githubTool)
    readOnly := getGitHubReadOnly(githubTool)
    toolsets := getGitHubToolsets(githubTool)
    yaml.WriteString("              \"github\": {\n")
    
    if githubType == "remote" {
        RenderGitHubMCPRemoteConfig(...)
    } else {
        RenderGitHubMCPDockerConfig(...)
    }
    
    if isLast {
        yaml.WriteString("              }\n")
    } else {
        yaml.WriteString("              },\n")
    }

Impact Analysis

  • Maintainability: Any change to GitHub MCP rendering rules must be replicated four times, increasing the chance the engine implementations drift apart.
  • Bug Risk: Fixes for token precedence or read-only handling can be missed in one engine, leading to subtle runtime differences.
  • Code Bloat: Roughly 150 lines of near-identical logic inflate the workflow package and obscure true engine-specific behavior.

Refactoring Recommendations

  1. Extract a shared GitHub MCP rendering helper

    • Centralize the remote/local branching and token resolution in engine_helpers.go (or a new helper) that accepts formatting options (JSON vs TOML, allowed tool handling, env passthrough).
    • Estimated effort: Medium (4–6h)
    • Benefits: Single source of truth, easier future fixes, consistent behavior across engines.
  2. Model GitHub MCP config as a shared struct

    • Populate a GitHubMCPConfig struct once per engine and pass it to format-specific writers (JSON/TOML) to eliminate repeated yaml.WriteString sequences.
    • Estimated effort: Medium (4h)
    • Benefits: Clear separation between data gathering and rendering, unlocks unit tests on shared logic.

Implementation Checklist

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

Analysis Metadata

  • Analyzed Files: 4
  • Detection Method: Serena semantic code analysis
  • Commit: 7658c86
  • Analysis Date: 2025-10-24T21:09:47Z

AI generated by Duplicate Code Detector

Metadata

Metadata

Assignees

No one assigned

    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