🔍 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
- 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
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 pull_request event detection
Analysis of commit 8c2337a
Assignee:
@copilotSummary
extractPullRequestEventPresenceFromOnFieldanddetectPullRequestEventshave byte-for-byte identical bodies (21 normalized lines). Both parse a workflowon:field into(hasPR, hasPRTarget)and both live in theworkflowpackage.Duplication Details
Pattern:
on:field → (pull_request, pull_request_target) presencepkg/workflow/safe_update_enforcement.go(lines 131-153,extractPullRequestEventPresenceFromOnField)pkg/workflow/safe_update_manifest.go(lines 182-207,detectPullRequestEvents)Impact Analysis
Refactoring Recommendations
detectPullRequestEvents) and haveextractPullRequestEventPresenceFromOnFielddelegate to it, or remove the duplicate and update the one caller (extractPullRequestEventPresenceFromCompiledWorkflow).on:event detection.Implementation Checklist
make fmtandmake test-unitAnalysis Metadata
pkg/non-test.gofiles