Part of duplicate code analysis: #4325
Summary
The "parse permission + log + wrap in MCP envelope" block inside callCollaboratorPermission (internal/server/unified.go) and restBackendCaller (internal/proxy/proxy.go) is nearly identical — ~15 lines of JSON-unmarshal, three-way log branch, and MCP wrapping copied between two different callers that ultimately perform the same GitHub REST enrichment.
Duplication Details
Pattern: Collaborator-permission JSON parse / log / MCP-wrap block
Impact Analysis
- Maintainability: A logging format change or a new field in the permission response (e.g.,
"role_name") must be made in two places. Historically these drifted — the unified.go copy includes owner/repo context in the message while proxy.go omits it, already showing divergence.
- Bug Risk: Low — both copies currently do the same thing, but the divergence in log messages is an early sign of drift.
- Code Bloat: ~15 lines × 2 sites = ~30 duplicated lines.
Refactoring Recommendations
-
Extract a logAndWrapCollaboratorPermission(body []byte, log logger, ...) interface{} helper
- Could live in
internal/server/unified.go, internal/proxy/proxy.go, or a shared internal package
- Accepts the raw
body, owner/repo/username strings, HTTP status code, and a logger function
- Returns the
mcpResp map
- Estimated effort: 1–2 hours
-
Alternatively, consolidate the two call paths so only one place makes the REST call for get_collaborator_permission. The guardBackendCaller in unified.go and the restBackendCaller in proxy.go appear to serve the same purpose for different server modes; a single shared implementation would remove the duplication entirely.
Implementation Checklist
Parent Issue
See parent analysis report: #4325
Related to #4325
Generated by Duplicate Code Detector · ● 2.6M · ◷
Part of duplicate code analysis: #4325
Summary
The "parse permission + log + wrap in MCP envelope" block inside
callCollaboratorPermission(internal/server/unified.go) andrestBackendCaller(internal/proxy/proxy.go) is nearly identical — ~15 lines of JSON-unmarshal, three-way log branch, and MCP wrapping copied between two different callers that ultimately perform the same GitHub REST enrichment.Duplication Details
Pattern: Collaborator-permission JSON parse / log / MCP-wrap block
Severity: Medium
Occurrences: 2
Locations:
internal/server/unified.go(lines ~338–354) —guardBackendCaller.callCollaboratorPermissioninternal/proxy/proxy.go(lines ~318–339) —restBackendCaller.CallTool(get_collaborator_permission branch)Duplicated Block (structure identical; only the logger variable differs):
Impact Analysis
"role_name") must be made in two places. Historically these drifted — theunified.gocopy includesowner/repocontext in the message whileproxy.goomits it, already showing divergence.Refactoring Recommendations
Extract a
logAndWrapCollaboratorPermission(body []byte, log logger, ...) interface{}helperinternal/server/unified.go,internal/proxy/proxy.go, or a shared internal packagebody, owner/repo/username strings, HTTP status code, and a logger functionmcpRespmapAlternatively, consolidate the two call paths so only one place makes the REST call for
get_collaborator_permission. TheguardBackendCallerinunified.goand therestBackendCallerinproxy.goappear to serve the same purpose for different server modes; a single shared implementation would remove the duplication entirely.Implementation Checklist
make testto verify no regressionsParent Issue
See parent analysis report: #4325
Related to #4325