[duplicate-code] Duplicate Code: pull_request event detection duplicated across safe_update files
维护者通常 1 天内回复
还没有人认领这个 Issue。
评估
调研方向
阅读 pkg/workflow/safe_update_enforcement.go 和 pkg/workflow/safe_update_manifest.go,然后追踪调用方 extractPullRequestEventPresenceFromCompiledWorkflow。合并重复的事件检测,并更新调用方以使用共享实现。运行 make fmt 和 make test-unit;只有 safe-update 强制执行和清单检测都仍然通过,才算完成。
由索引模型根据 Issue 内容生成。
描述
🔍 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
- 主要语言
- Go
- 星标
- 5.4k
- 派生
- 576
- 平均合并
- 8 小时 29 分钟
- 30 天内合并 PR
- 783
环境准备
在浏览器里用你自己的 GitHub 账号启动这个项目的开发容器。
- 提供 Dockerfile 或 Docker Compose 文件
- 没有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
github/gh-aw 的其他 Issue
-
[deep-report] Migrate manual os.Setenv/Unsetenv restore patterns to t.Setenv in 2 pkg/cli test files未关闭automation code-quality cookie deep-report improvement quick-win task-mining
难度 2/5 1 小时以内 新手友好度 85/100
维护者通常 1 天内回复
-
automation code-quality cookie deep-report improvement quick-win task-mining
难度 2/5 1 小时以内 新手友好度 82/100
维护者通常 1 天内回复
-
automation code-quality cookie deep-report improvement quick-win task-mining
难度 2/5 1 小时以内 新手友好度 76/100
维护者通常 1 天内回复
-
ai-generated cookie high-priority security
难度 2/5 1-3 小时 新手友好度 68/100
维护者通常 1 天内回复
-
automation cli cookie documentation
难度 2/5 1-3 小时 新手友好度 78/100
维护者通常 1 天内回复
相似的 Issue
-
Change wording for init command success message可能已有人在做 关联的 PR 仍在进行中或已合并。 未关闭
难度 1/5 1 小时以内 新手友好度 82/100
维护者通常 1 天内回复
-
enhancement pkg:sdk
难度 2/5 1-3 小时 新手友好度 80/100
aws/aws-durable-execution-sdk-go#144 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 78/100
cloudflare/cloudflared#1761 ·
-
难度 2/5 1-3 小时 新手友好度 72/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 72/100
维护者通常 1 天内回复