🔍 Duplicate Code Detected: Cross-Repo Target Parsing in Safe-Output Config Parsers
Analysis of commit 4845f00caf4609afc9cd34cbb45ad4b8ae621a20 (current shallow snapshot; parent commit range was unavailable in the runner)
Assignee: @copilot
Summary
Several safe-output config parsers repeat the same target-parsing scaffold: parse target, validate target-repo, parse allowed-repos, then continue with tool-specific fields. This pattern appears across multiple handlers and looks ready for a shared helper similar to the existing update-entity/create-entity parser abstractions.
Duplication Details
Pattern: repeated target / target-repo / allowed-repos parsing blocks
- Severity: Medium
- Occurrences: 4 clear instances in the inspected review/project handlers
- Locations:
pkg/workflow/create_pr_review_comment.go (lines 31-64)
pkg/workflow/reply_to_pr_review_comment.go (lines 24-64)
pkg/workflow/submit_pr_review.go (lines 38-56)
pkg/workflow/update_project.go (lines 41-67)
- Code Sample:
if target, exists := configMap["target"]; exists {
if targetStr, ok := target.(string); ok {
config.Target = targetStr
}
}
targetRepoSlug, isInvalid := parseTargetRepoWithValidation(configMap)
if isInvalid {
return nil
}
config.TargetRepoSlug = targetRepoSlug
config.AllowedRepos = ParseStringArrayFromConfig(configMap, "allowed-repos", log)
The surrounding defaults and tool-specific fields differ, but the cross-repo targeting portion is effectively copy-pasted.
Impact Analysis
- Maintainability: Cross-repo policy changes need to be duplicated across multiple parser functions.
- Bug Risk: Handlers can diverge on wildcard handling,
allowed-repos parsing, or early-return behavior.
- Code Bloat: Repeated target parsing hides the tool-specific behavior each parser is supposed to express.
Refactoring Recommendations
-
Introduce a shared target-config parser helper
- Extract common functionality to:
pkg/workflow/config_helpers.go or a focused safe-output parsing helper file
- Estimated effort: 2-4 hours
- Benefits: centralizes wildcard policy, repo validation, and
allowed-repos decoding
-
Parameterize helper behavior for tools that allow or forbid specific fields
- Extract common functionality to: a helper that returns
(target, targetRepoSlug, allowedRepos, ok) and accepts small options for allowed wildcard/target semantics
- Estimated effort: 3-5 hours
- Benefits: keeps parser bodies short and makes policy differences explicit instead of implicit
Implementation Checklist
Analysis Metadata
- Analyzed Files: 4 directly inspected files 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: Cross-Repo Target Parsing in Safe-Output Config Parsers
Analysis of commit
4845f00caf4609afc9cd34cbb45ad4b8ae621a20(current shallow snapshot; parent commit range was unavailable in the runner)Assignee:
@copilotSummary
Several safe-output config parsers repeat the same target-parsing scaffold: parse
target, validatetarget-repo, parseallowed-repos, then continue with tool-specific fields. This pattern appears across multiple handlers and looks ready for a shared helper similar to the existing update-entity/create-entity parser abstractions.Duplication Details
Pattern: repeated target / target-repo / allowed-repos parsing blocks
pkg/workflow/create_pr_review_comment.go(lines 31-64)pkg/workflow/reply_to_pr_review_comment.go(lines 24-64)pkg/workflow/submit_pr_review.go(lines 38-56)pkg/workflow/update_project.go(lines 41-67)The surrounding defaults and tool-specific fields differ, but the cross-repo targeting portion is effectively copy-pasted.
Impact Analysis
allowed-reposparsing, or early-return behavior.Refactoring Recommendations
Introduce a shared target-config parser helper
pkg/workflow/config_helpers.goor a focused safe-output parsing helper fileallowed-reposdecodingParameterize helper behavior for tools that allow or forbid specific fields
(target, targetRepoSlug, allowedRepos, ok)and accepts small options for allowed wildcard/target semanticsImplementation Checklist
Analysis Metadata
PATH; findings were verified with targeted source inspection and pattern search fallback4845f00caf4609afc9cd34cbb45ad4b8ae621a202026-08-18T00:00:00Z