Hacktoberfest 2026: los issues que los mantenedores marcaron para octubre, abiertos y aptos para principiantes. Explorar issues de Hacktoberfest

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

Abierto Apto para principiantes
#67,005 0 comentarios 0 reacciones 0 asignados Ver en GitHub

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
Tipo de issue
Refactorización
Claridad
Bien especificado
Estado de actividad
Activo
Stack tecnológico
github-actions, go
Área
devtools

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

automated-analysis code-quality cookie refactoring
🔍 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
Lenguaje dominante
Go
Estrellas
5.4k
Forks
576
Merge medio
8 h 29 min
PR fusionados (30 d)
783

Preparar el entorno

Abrir en Codespaces

Inicia el contenedor de desarrollo del proyecto en tu navegador, con tu propia cuenta de GitHub.

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de github/gh-aw

Todos los issues de github/gh-aw

Issues similares

Más issues de Go

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.