Summary
configureCustomJobSteps and applyBuiltinJobPreSteps both collect setup-steps and pre-steps, call extractPinnedJobSteps, and then splice those lists into job steps with nearly identical control flow.
Duplication Details
pkg/workflow/compiler_jobs.go:960-1003
pkg/workflow/compiler_jobs.go:1028-1080
Impact
- Future changes to step ordering or validation now need to be updated in two places.
- The duplicated branching increases the risk of custom and built-in jobs drifting apart.
Refactoring Recommendation
Extract a shared helper that loads setup-steps / pre-steps once and returns the normalized slices plus insertion intent. Keep the job-specific validation and target-job lookup separate, but centralize the extraction and insertion flow.
Code Sample
if hasSetupStepsField {
setupSteps, err = c.extractPinnedJobSteps("setup-steps", jobName, configMap, data)
}
if hasPreStepsField {
preSteps, err = c.extractPinnedJobSteps("pre-steps", jobName, configMap, data)
}
...
job.Steps = insertPreStepsAtEarliestBoundary(job.Steps, preSteps)
job.Steps = insertSetupStepsAtStart(job.Steps, setupSteps)
Analysis Metadata
- Commit: 27e0d8d
- Detection Method: Serena semantic code analysis + local source inspection
Generated by 🔍 Duplicate Code Detector · 78.6 AIC · ⌖ 12.1 AIC · ⊞ 14.8K · ◷
Summary
configureCustomJobStepsandapplyBuiltinJobPreStepsboth collectsetup-stepsandpre-steps, callextractPinnedJobSteps, and then splice those lists into job steps with nearly identical control flow.Duplication Details
pkg/workflow/compiler_jobs.go:960-1003pkg/workflow/compiler_jobs.go:1028-1080Impact
Refactoring Recommendation
Extract a shared helper that loads
setup-steps/pre-stepsonce and returns the normalized slices plus insertion intent. Keep the job-specific validation and target-job lookup separate, but centralize the extraction and insertion flow.Code Sample
Analysis Metadata