Skip to content

[duplicate-code] Extract shared cross-repo target parsing from safe output config handlers #53839

Description

@github-actions

🔍 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

  1. 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
  2. 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

  • Review duplication findings
  • Prioritize refactoring tasks
  • Create refactoring plan
  • Implement changes
  • Update tests
  • Verify no functionality broken
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 ·

  • expires on Aug 20, 2026, 2:02 PM UTC-08:00

Metadata

Metadata

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions