[duplicate-code] Duplicate Code: pull_request event detection duplicated across safe_update files
Maintainer thường phản hồi trong vòng 1 ngày
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 2/5
- Thời gian dự kiến
- 1-3 giờ
- Mức phù hợp với người mới
- 68/100
Hướng nghiên cứu
Đọc hai helper được nêu trong pkg/workflow/safe_update_enforcement.go và pkg/workflow/safe_update_manifest.go, sau đó kiểm tra các hàm gọi chúng được liệt kê trong issue. Cập nhật hàm gọi trong manifest để sử dụng helper chuẩn và xóa phần trùng lặp. Chạy make fmt và make test-unit; công việc hoàn tất khi logic phát hiện dùng chung vẫn được sử dụng và các bài kiểm thử safe-update đều đạt.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
🔍 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 }extractPullRequestEventPresenceFromOnFieldis 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
- Keep a single detection helper
- Remove
detectPullRequestEventsand route its caller toextractPullRequestEventPresenceFromOnField(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.
- Remove
Implementation Checklist
- Review duplication findings
- Choose a single canonical helper name/location
- Update
safe_update_manifest.go:131to use it - Remove the duplicate function
- Run
make fmtandmake 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
- Ngôn ngữ chính
- Go
- Star
- 5.5k
- Fork
- 606
- Merge trung bình
- 4 giờ 13 phút
- Pull request đã merge (30 ngày)
- 823
Chuẩn bị môi trường
Khởi chạy dev container của dự án ngay trên trình duyệt, bằng tài khoản GitHub của bạn.
- Có Dockerfile hoặc tệp Docker Compose
- Không có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của github/gh-aw
-
[doc-healer] DDUw improvement: retry integrity-filtered issue reads with direct single-item lookupsĐang mởautomation documentation
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
Maintainer thường phản hồi trong vòng 1 ngày
-
automated-analysis code-quality cookie testing
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
Maintainer thường phản hồi trong vòng 1 ngày
-
ai-inspected
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
Maintainer thường phản hồi trong vòng 1 ngày
-
agent-research
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
Maintainer thường phản hồi trong vòng 1 ngày
-
automation cli cookie documentation
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
github/gh-aw#72447 · 3 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
Issue tương tự
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 66/100
-
Energy flow: add an "Other" row so the consumers add up to the consumption totalCó thể đã có người làm @github-actions đã nhận hôm nay. Đang mởenhancement
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 73/100
evcc-io/evcc#35512 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 74/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
nebari-dev/nebi#630 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
router-for-me/CLIProxyAPI#7084 ·
Maintainer thường phản hồi trong vòng 1 ngày