Skip to content

[duplicate-code] Duplicate Code: pull_request event detection duplicated across safe_update files #67005

Description

@github-actions

🔍 Duplicate Code Detected: Duplicate pull_request event detection

Analysis of commit 8c2337a

Assignee: @copilot

Summary

extractPullRequestEventPresenceFromOnField and detectPullRequestEvents have byte-for-byte identical bodies (21 normalized lines). Both parse a workflow on: field into (hasPR, hasPRTarget) and both live in the workflow package.

Duplication Details

Pattern: on: field → (pull_request, pull_request_target) presence

  • Severity: Medium
  • Occurrences: 2
  • Locations:
    • pkg/workflow/safe_update_enforcement.go (lines 131-153, extractPullRequestEventPresenceFromOnField)
    • pkg/workflow/safe_update_manifest.go (lines 182-207, detectPullRequestEvents)
  • Code Sample:
    func detectPullRequestEvents(onField any) (hasPR bool, hasPRTarget bool) {
        switch v := onField.(type) {
        case string:
            return v == "pull_request", v == "pull_request_target"
        case []any:
            for _, item := range v {
                event, ok := item.(string)
                if !ok { continue }
                if event == "pull_request" { hasPR = true }
                if event == "pull_request_target" { hasPRTarget = true }
            }
        case map[string]any:
            _, hasPR = v["pull_request"]
            _, hasPRTarget = v["pull_request_target"]
        }
        return hasPR, hasPRTarget
    }

Impact Analysis

  • Maintainability: Event-parsing changes must be mirrored across two files.
  • Bug Risk: The two copies can diverge, causing inconsistent safe-update enforcement vs manifest detection.
  • Code Bloat: ~23 duplicated lines across two files in the same package.

Refactoring Recommendations

  1. Extract a single shared helper
    • Keep one function (e.g. detectPullRequestEvents) and have extractPullRequestEventPresenceFromOnField delegate to it, or remove the duplicate and update the one caller (extractPullRequestEventPresenceFromCompiledWorkflow).
    • Estimated effort: ~15 min, low complexity.
    • Benefits: single source of truth for on: event detection.

Implementation Checklist

  • Collapse to one implementation and update callers
  • Run make fmt and make test-unit
  • Verify safe-update enforcement and manifest detection unaffected
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:44.532Z.

    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