🔍 Duplicate Code Detected: Repo Parameter Extraction Switch
Analysis of commit 4845f00caf4609afc9cd34cbb45ad4b8ae621a20 (current shallow snapshot; parent commit range was unavailable in the runner)
Assignee: @copilot
Summary
addRepoParameterIfNeeded repeats the same AllowedRepos / TargetRepoSlug extraction logic for each safe-output tool name. The function currently carries a large manual dispatch table where most branches differ only by the field path, which makes this code expensive to extend and easy to update inconsistently.
Duplication Details
Pattern: repeated per-tool repo-target extraction
- Severity: Medium
- Occurrences: 20+ repeated extraction branches in one function
- Locations:
pkg/workflow/safe_outputs_tools_repo_params.go (lines 17-157)
pkg/workflow/safe_outputs_tools_repo_params.go (lines 196-207) reuses the same mutation path indirectly through a scratch tool
- Code Sample:
if config := safeOutputs.CreateIssues; config != nil {
hasAllowedRepos = len(config.AllowedRepos) > 0
targetRepoSlug = config.TargetRepoSlug
}
...
if config := safeOutputs.AddLabels; config != nil {
hasAllowedRepos = len(config.AllowedRepos) > 0
targetRepoSlug = config.TargetRepoSlug
}
The same two assignments are repeated across create, close, update, label, review, milestone, and assignment tool cases.
Impact Analysis
- Maintainability: Adding a new safe-output tool requires hand-editing a long switch instead of registering a single extractor.
- Bug Risk: It is easy for one branch to drift and forget either
AllowedRepos or TargetRepoSlug, which would silently change tool schema generation.
- Code Bloat: The switch obscures the actual decision logic because most of the function body is repeated plumbing.
Refactoring Recommendations
-
Extract a shared repo-target accessor helper
- Extract common functionality to:
pkg/workflow/safe_outputs_tools_repo_params.go
- Estimated effort: 2-4 hours
- Benefits: one code path for
AllowedRepos/TargetRepoSlug, easier review when new tools are added
-
Replace the switch with a lookup table or interface-based registry
- Extract common functionality to: a small map from tool name to accessor closure, or a shared interface implemented by config structs that expose repo targeting
- Estimated effort: 3-5 hours
- Benefits: removes copy-paste branches and makes missing tool coverage obvious in tests
Implementation Checklist
Analysis Metadata
- Analyzed Files: 1 directly inspected file for this pattern; repo-wide search across 1,249 non-test Go files in the snapshot
- Detection Method: Serena activation succeeded, but Go LSP could not start because Go was unavailable in
PATH; findings were verified with targeted source inspection and pattern search fallback
- Commit:
4845f00caf4609afc9cd34cbb45ad4b8ae621a20
- Analysis Date:
2026-08-18T00:00:00Z
Generated by 🔍 Duplicate Code Detector · gpt54 · 163.8 AIC · ⊞ 13.1K · ◷
🔍 Duplicate Code Detected: Repo Parameter Extraction Switch
Analysis of commit
4845f00caf4609afc9cd34cbb45ad4b8ae621a20(current shallow snapshot; parent commit range was unavailable in the runner)Assignee:
@copilotSummary
addRepoParameterIfNeededrepeats the sameAllowedRepos/TargetRepoSlugextraction logic for each safe-output tool name. The function currently carries a large manual dispatch table where most branches differ only by the field path, which makes this code expensive to extend and easy to update inconsistently.Duplication Details
Pattern: repeated per-tool repo-target extraction
pkg/workflow/safe_outputs_tools_repo_params.go(lines 17-157)pkg/workflow/safe_outputs_tools_repo_params.go(lines 196-207) reuses the same mutation path indirectly through a scratch toolThe same two assignments are repeated across create, close, update, label, review, milestone, and assignment tool cases.
Impact Analysis
AllowedReposorTargetRepoSlug, which would silently change tool schema generation.Refactoring Recommendations
Extract a shared repo-target accessor helper
pkg/workflow/safe_outputs_tools_repo_params.goAllowedRepos/TargetRepoSlug, easier review when new tools are addedReplace the switch with a lookup table or interface-based registry
Implementation Checklist
Analysis Metadata
PATH; findings were verified with targeted source inspection and pattern search fallback4845f00caf4609afc9cd34cbb45ad4b8ae621a202026-08-18T00:00:00Z