Skip to content

[duplicate-code] Duplicate Code: reserved needs-target job list duplicated across validators #67006

Description

@github-actions

🔍 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

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

  • Extract a single shared predicate and update both call sites
  • Run make fmt and make test-unit
  • Verify both needs-validation paths still reject reserved targets
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 · ◷

  • expires on Oct 10, 2026, 1:57 PM UTC-08:00

Activity

  1. github-actions commented on Oct 10, 2026

    @github-actions
    ContributorAuthor

    This issue was automatically closed because it expired on 2026-10-10T21:57:46.770Z.

    Closed by Workflow

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions