Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

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

未关闭 适合新手
#67,005 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
68/100
Issue 类型
重构
描述清晰度
描述清楚
活跃度
活跃
技术栈
github-actions, go
领域
devtools

调研方向

阅读 pkg/workflow/safe_update_enforcement.go 和 pkg/workflow/safe_update_manifest.go,然后追踪调用方 extractPullRequestEventPresenceFromCompiledWorkflow。合并重复的事件检测,并更新调用方以使用共享实现。运行 make fmt 和 make test-unit;只有 safe-update 强制执行和清单检测都仍然通过,才算完成。

由索引模型根据 Issue 内容生成。

描述

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
主要语言
Go
星标
5.4k
派生
576
平均合并
8 小时 29 分钟
30 天内合并 PR
783

环境准备

在 Codespaces 中打开

在浏览器里用你自己的 GitHub 账号启动这个项目的开发容器。

  • 提供 Dockerfile 或 Docker Compose 文件
  • 没有 Pull Request 模板
  • 阅读贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

github/gh-aw 的其他 Issue

查看 github/gh-aw 的全部 Issue

相似的 Issue

更多 Go Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。