🔍 Duplicate Code Detected: Safe Output Workflow Env Setup
Analysis of commit 15fc225
Assignee: @copilot
Summary
Multiple safe-output job builders duplicate the same workflow metadata and token setup logic before invoking buildSafeOutputJob. The repeated blocks make it harder to keep environment variables and token handling consistent when behavior changes.
Duplication Details
Pattern: Repeated safe-output workflow metadata and token setup
- Severity: Medium
- Occurrences: 4
- Locations:
pkg/workflow/add_comment.go:36
pkg/workflow/create_issue.go:71
pkg/workflow/create_pr_review_comment.go:23
pkg/workflow/create_discussion.go:65
- Code Sample:
var customEnvVars []string
customEnvVars = append(customEnvVars, fmt.Sprintf(" GH_AW_WORKFLOW_NAME: %q\n", data.Name))
if data.Source != "" {
customEnvVars = append(customEnvVars, fmt.Sprintf(" GH_AW_WORKFLOW_SOURCE: %q\n", data.Source))
sourceURL := buildSourceURL(data.Source)
if sourceURL != "" {
customEnvVars = append(customEnvVars, fmt.Sprintf(" GH_AW_WORKFLOW_SOURCE_URL: %q\n", sourceURL))
}
}
customEnvVars = append(customEnvVars, buildSafeOutputJobEnvVars(
c.trialMode,
c.trialLogicalRepoSlug,
data.SafeOutputs.Staged,
data.SafeOutputs.AddComments.TargetRepoSlug,
)...)
var token string
if data.SafeOutputs.AddComments != nil {
token = data.SafeOutputs.AddComments.GitHubToken
}
Impact Analysis
- Maintainability: Hard to change workflow metadata behavior without touching every safe-output job builder.
- Bug Risk: Divergent env var lists or token handling can slip in when individual files evolve separately.
- Code Bloat: Adds ~15 identical lines per job, increasing review burden.
Refactoring Recommendations
- Extract shared helper for workflow metadata env vars
- Extract to
pkg/workflow/safe_outputs_helpers.go
- Estimated effort: 2-3h
- Benefits: Single point of truth for workflow name/source env vars and common token retrieval.
- Provide typed config for
buildSafeOutputJob
- Extend
SafeOutputJobConfig to accept workflow metadata flags instead of raw slices
- Estimated effort: 3-4h
- Benefits: Reduces manual env-manipulation and keeps job setup consistent.
Implementation Checklist
Analysis Metadata
- Analyzed Files: 4
- Detection Method: Serena semantic code analysis
- Commit: 15fc225
- Analysis Date: 2025-11-10 21:07:24Z
AI generated by Duplicate Code Detector
🔍 Duplicate Code Detected: Safe Output Workflow Env Setup
Analysis of commit 15fc225
Assignee:
@copilotSummary
Multiple safe-output job builders duplicate the same workflow metadata and token setup logic before invoking
buildSafeOutputJob. The repeated blocks make it harder to keep environment variables and token handling consistent when behavior changes.Duplication Details
Pattern: Repeated safe-output workflow metadata and token setup
pkg/workflow/add_comment.go:36pkg/workflow/create_issue.go:71pkg/workflow/create_pr_review_comment.go:23pkg/workflow/create_discussion.go:65Impact Analysis
Refactoring Recommendations
pkg/workflow/safe_outputs_helpers.gobuildSafeOutputJobSafeOutputJobConfigto accept workflow metadata flags instead of raw slicesImplementation Checklist
Analysis Metadata