[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 pkg/workflow/safe_update_enforcement.go y pkg/workflow/safe_update_manifest.go y luego rastrea el llamador extractPullRequestEventPresenceFromCompiledWorkflow. Consolida la detección duplicada de eventos y actualiza los llamadores para que usen la implementación compartida. Ejecuta make fmt y make test-unit; el trabajo estará hecho cuando tanto la aplicación de safe-update como la detección del manifiesto sigan pasando.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
🔍 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 haveextractPullRequestEventPresenceFromOnFielddelegate 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.
- Keep one function (e.g.
Implementation Checklist
- Collapse to one implementation and update callers
- Run
make fmtandmake test-unit - Verify safe-update enforcement and manifest detection unaffected
Analysis Metadata
- Analyzed Area:
pkg/non-test.gofiles - 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
- 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
-
[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
-
automation cli cookie documentation
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
Los mantenedores suelen responder en 1 día
Todos los issues de github/gh-aw
Issues similares
-
enhancement exporter/awss3 needs triage
Dificultad 2/5 1-3 horas Aptitud para principiantes 66/100
open-telemetry/opentelemetry-collector-contrib#51905 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
area/docs theme/validation
Dificultad 1/5 1-3 horas Aptitud para principiantes 88/100
Los mantenedores suelen responder en 1 día
-
Add skip-to-content linkAbiertoa11y P1-significant
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
Los mantenedores suelen responder en 1 día
-
[correctness][missing-coverage][sort] Strict uniqueness checks lack numeric-key equivalence coverageAbierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 77/100
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 83/100
infiniflow/ragflow#20625 · 1 reacción ·
Los mantenedores suelen responder en 1 día