Skip to content

[duplicate-code] Duplicate Code: Safe-output parser wrappers repeated across workflow handlers #52155

Description

@github-actions

🔍 Duplicate Code Detected: Safe-Output Parser Wrappers

Analysis of commit c993af6

Assignee: @copilot

Summary

Many safe-output handlers already rely on the shared parseConfigScaffold helper, but each caller still repeats the same outer wrapper structure: optional preprocessing, the parseConfigScaffold(...) call, nil/default handling, and a small amount of post-parse logging or policy wiring. This pattern appears in at least 16 non-test Go files under pkg/workflow.

📊 Duplication Details - 2026-08-11

Duplication Details

Pattern: parseConfigScaffold wrapper functions

  • Severity: Medium
  • Occurrences: 16 wrappers
  • Locations:
    • pkg/workflow/add_labels.go:23 (parseAddLabelsConfig)
    • pkg/workflow/assign_to_user.go:40 (parseAssignToUserConfig)
    • pkg/workflow/unassign_from_user.go:19 (parseUnassignFromUserConfig)
    • pkg/workflow/set_issue_field.go:17 (parseSetIssueFieldConfig)
    • pkg/workflow/set_issue_type.go:19 (parseSetIssueTypeConfig)
    • pkg/workflow/mark_pull_request_as_ready_for_review.go:19 (parseMarkPullRequestAsReadyForReviewConfig)
  • Code Sample:
config := parseConfigScaffold(outputMap, "set-issue-type", setIssueTypeLog, func(err error) *SetIssueTypeConfig {
    setIssueTypeLog.Printf("Failed to unmarshal set-issue-type config, disabling handler: %v", err)
    return nil
})
if config != nil {
    setIssueTypeLog.Printf("Parsed configuration: allowed_count=%d, target=%s", len(config.Allowed), config.Target)
}
return config

Impact Analysis

  • Maintainability: Error-policy changes and defaulting rules have to be copied into many wrappers instead of changed once.
  • Bug Risk: Handler behavior can drift when one wrapper gets a default-max or postprocessing fix that peers miss.
  • Code Bloat: The shared parsing intent is hidden behind many nearly identical file-level wrappers.

Refactoring Recommendations

  1. Add a higher-level scaffold for common parser policies

    • Extend pkg/workflow/config_helpers.go with a descriptor-based helper for fallback policy, default max handling, and post-parse hooks.
    • Estimated effort: medium.
    • Benefits: one place for parse failure behavior and common postprocessing.
  2. Group simple handlers behind declarative parser descriptors

    • Convert the most repetitive wrappers first (add-labels, remove-labels, set-issue-*, assign/unassign).
    • Estimated effort: medium.
    • Benefits: smaller handler files and lower drift risk.

Implementation Checklist

  • Inventory current parseConfigScaffold callers by fallback policy
  • Introduce shared hooks for default max and target/filter postprocessing
  • Migrate low-complexity handlers first
  • Keep bespoke wrappers only where preprocessing is genuinely unique
  • Update parser tests around shared helper behavior

Analysis Metadata

  • Analyzed Files: 1220 changed non-test Go files, with semantic focus on pkg/workflow
  • Detection Method: Serena semantic code analysis plus targeted pattern search
  • Commit: c993af6e74f88f7b414d54580b94f3f545b32864
  • Analysis Date: 2026-08-11T22:09:51Z

Warning

Firewall blocked 1 domain

The following domain was blocked by the firewall during workflow execution:

  • proxy.golang.org

To allow these domains, add them to the network.allowed list in your workflow frontmatter:

network:
  allowed:
    - defaults
    - "proxy.golang.org"

See Network Configuration for more information.

Generated by 🔍 Duplicate Code Detector · gpt54 · 118.3 AIC · ⊞ 12.8K ·

  • expires on Aug 13, 2026, 2:13 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