🔍 Duplicate Code Detected: Duplicate reserved-needs-target job list
Analysis of commit 8c2337a
Assignee: @copilot
Summary
isReservedSafeOutputsNeedsTarget and isReservedOnNeedsTarget have byte-for-byte identical bodies (16 normalized lines). Both check whether a job name is a reserved internal job, enumerating the exact same case list. Both live in the workflow package.
Duplication Details
Pattern: reserved internal job-name allowlist
- Severity: Medium
- Occurrences: 2
- Locations:
pkg/workflow/safe_outputs_needs_validation.go (lines 68-84, isReservedSafeOutputsNeedsTarget)
pkg/workflow/on_needs_validation.go (lines 308-324, isReservedOnNeedsTarget)
- Code Sample:
func isReservedOnNeedsTarget(jobName string) bool {
switch jobName {
case string(constants.AgentJobName),
string(constants.ActivationJobName),
string(constants.PreActivationJobName),
"pre-activation",
string(constants.ConclusionJobName),
string(constants.SafeOutputsJobName),
"safe-outputs",
string(constants.DetectionJobName),
string(constants.UnlockJobName),
"push_repo_memory",
"update_cache_memory":
return true
default:
return false
}
}
Impact Analysis
- Maintainability: Adding or renaming a reserved job requires editing two identical lists.
- Bug Risk: High — if one list is updated and the other is not,
on: needs validation and safe-outputs needs validation will disagree about reserved job names.
- Code Bloat: ~34 duplicated lines across two files in the same package.
Refactoring Recommendations
- Single shared predicate
- Define one
isReservedNeedsTarget(jobName string) bool (e.g. in a shared validation helper) and have both call sites delegate to it.
- Estimated effort: ~15 min, low complexity.
- Benefits: one authoritative reserved-job list; eliminates drift risk between the two validators.
Implementation Checklist
Analysis Metadata
- Analyzed Area:
pkg/ non-test .go files
- Detection Method: normalized function-body hashing + manual verification
- Commit: 8c2337a
Generated by 🔍 Duplicate Code Detector · pi · opus48 · 52.6 AIC · ⌖ 40.5 AIC · ⊞ 1.5K · ◷
🔍 Duplicate Code Detected: Duplicate reserved-needs-target job list
Analysis of commit 8c2337a
Assignee:
@copilotSummary
isReservedSafeOutputsNeedsTargetandisReservedOnNeedsTargethave byte-for-byte identical bodies (16 normalized lines). Both check whether a job name is a reserved internal job, enumerating the exact samecaselist. Both live in theworkflowpackage.Duplication Details
Pattern: reserved internal job-name allowlist
pkg/workflow/safe_outputs_needs_validation.go(lines 68-84,isReservedSafeOutputsNeedsTarget)pkg/workflow/on_needs_validation.go(lines 308-324,isReservedOnNeedsTarget)Impact Analysis
on:needs validation and safe-outputs needs validation will disagree about reserved job names.Refactoring Recommendations
isReservedNeedsTarget(jobName string) bool(e.g. in a shared validation helper) and have both call sites delegate to it.Implementation Checklist
make fmtandmake test-unitAnalysis Metadata
pkg/non-test.gofiles