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

Cerrado Apto para principiantes
#66,295 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
security, tooling

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

automated-analysis code-quality cookie duplication
🔍 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
    }
    
    extractPullRequestEventPresenceFromOnField is 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
  1. Keep a single detection helper
    • Remove detectPullRequestEvents and route its caller to extractPullRequestEventPresenceFromOnField (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.
Implementation Checklist
  • Review duplication findings
  • Choose a single canonical helper name/location
  • Update safe_update_manifest.go:131 to use it
  • Remove the duplicate function
  • Run make fmt and make 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

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.