Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

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

Aperta Adatta ai principianti
#67,005 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
68/100
Tipo di issue
Refactoring
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
github-actions, go
Ambito
devtools

Direzione di ricerca

Leggi pkg/workflow/safe_update_enforcement.go e pkg/workflow/safe_update_manifest.go, quindi segui il chiamante extractPullRequestEventPresenceFromCompiledWorkflow. Consolida il rilevamento duplicato degli eventi e aggiorna i chiamanti affinché usino l’implementazione condivisa. Esegui make fmt e make test-unit; il lavoro è completato quando sia l’applicazione di safe-update sia il rilevamento del manifest continuano a passare.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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
Lingua principale
Go
Stelle
5.4k
Fork
576
Merge medio
8h 11m
PR unite (30g)
798

Preparare l'ambiente

Apri in Codespaces

Avvia il container di sviluppo del progetto nel browser, con il tuo account GitHub.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di github/gh-aw

Tutte le issue di github/gh-aw

Issue simili

Altre issue su Go

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.