[duplicate-code] Duplicate Code: pull_request event detection duplicated across safe_update files
Los mantenedores suelen responder en 1 día
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 2/5
- Tiempo estimado
- 1-3 horas
- Aptitud para principiantes
- 68/100
Línea de trabajo
Lee los dos helpers mencionados en pkg/workflow/safe_update_enforcement.go y pkg/workflow/safe_update_manifest.go; después, comprueba sus llamadores enumerados en el issue. Actualiza el llamador del manifiesto para que use el helper canónico y elimina el duplicado. Ejecuta make fmt y make test-unit; el trabajo estará terminado cuando la lógica de detección compartida siga utilizándose y pasen las pruebas de safe-update.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
🔍 Duplicate Code Detected: Duplicated pull_request event detection
Analysis of commit 3fd44f8
Assignee: @copilot
Summary
Two functions in the workflow package implement identical logic (22 lines) to detect whether an on: field declares pull_request / pull_request_target events. They were copy-pasted across two files rather than shared.
Duplication Details
Pattern: on field -> (hasPR, hasPRTarget)
- Severity: Medium
- Occurrences: 2 (exact duplicate, different files, same package)
- Locations:
pkg/workflow/safe_update_enforcement.go(lines 131-153,extractPullRequestEventPresenceFromOnField)pkg/workflow/safe_update_manifest.go(lines 182-204,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 }extractPullRequestEventPresenceFromOnFieldis identical except for its name.
Both live in package workflow, so one can directly call the other with no import changes. Current callers: compiler.go:639 and safe_update_enforcement.go:164 use the first; safe_update_manifest.go:131 uses the second.
Impact Analysis
- Maintainability: Event-shape handling (string / array / map) must be kept in sync in two files.
- Bug Risk: High for a correctness-sensitive area — safe-update enforcement depends on accurate PR-event detection; divergence could weaken a security check.
- Code Bloat: ~22 redundant lines.
Refactoring Recommendations
- Keep a single detection helper
- Remove
detectPullRequestEventsand route its caller toextractPullRequestEventPresenceFromOnField(or move the shared helper to a neutral location and have both files call it). - Estimated effort: ~20 min, low complexity.
- Benefits: one source of truth for a security-relevant check, −22 lines.
- Remove
Implementation Checklist
- Review duplication findings
- Choose a single canonical helper name/location
- Update
safe_update_manifest.go:131to use it - Remove the duplicate function
- Run
make fmtandmake test-unit - Verify safe-update enforcement tests still pass
Analysis Metadata
- Analyzed Files: pkg/ (1435 non-test .go files)
- Detection Method: Serena semantic code analysis + function-body fingerprinting
- Commit: 3fd44f8
- Analysis Date: 2026-10-06
Generated by 🔍 Duplicate Code Detector · pi · opus48 · 74.5 AIC · ⌖ 41.3 AIC · ⊞ 1.5K · ◷
- expires on Oct 8, 2026, 1:56 PM UTC-08:00
- Lenguaje dominante
- Go
- Estrellas
- 5.4k
- Forks
- 576
- Merge medio
- 8 h 29 min
- PR fusionados (30 d)
- 783
Preparar el entorno
Inicia el contenedor de desarrollo del proyecto en tu navegador, con tu propia cuenta de GitHub.
- Incluye un Dockerfile o un archivo de Docker Compose
- Sin plantilla de pull request
- Leer la guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de github/gh-aw
-
[duplicate-code] Duplicate Code: pull_request event detection duplicated across safe_update filesAbiertoautomated-analysis code-quality cookie refactoring
Dificultad 2/5 1-3 horas Aptitud para principiantes 68/100
Los mantenedores suelen responder en 1 día
-
[deep-report] Migrate manual os.Setenv/Unsetenv restore patterns to t.Setenv in 2 pkg/cli test filesAbiertoautomation code-quality cookie deep-report improvement quick-win task-mining
Dificultad 2/5 Menos de una hora Aptitud para principiantes 85/100
Los mantenedores suelen responder en 1 día
-
[deep-report] Migrate os.Chdir+t.Parallel() test patterns to t.Chdir in 5 pkg/cli test filesAbiertoautomation code-quality cookie deep-report improvement quick-win task-mining
Dificultad 2/5 Menos de una hora Aptitud para principiantes 82/100
Los mantenedores suelen responder en 1 día
-
automation code-quality cookie deep-report improvement quick-win task-mining
Dificultad 2/5 Menos de una hora Aptitud para principiantes 76/100
Los mantenedores suelen responder en 1 día
-
ai-generated cookie high-priority security
Dificultad 2/5 1-3 horas Aptitud para principiantes 68/100
github/gh-aw#66933 · 12 comentarios ·
Los mantenedores suelen responder en 1 día
Todos los issues de github/gh-aw
Issues similares
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
Los mantenedores suelen responder en 1 día
-
Broken Claude manifestAbierto
Dificultad 1/5 Menos de una hora Aptitud para principiantes 88/100
-
[Chore] Remove dead AutogenV2 feature flagPosiblemente ocupada @geeknishantkyeus la tomó hoy. Abiertobug triage
Dificultad 2/5 1-3 horas Aptitud para principiantes 75/100
kyverno/kyverno#17936 · 1 comentario · 1 reacción ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100