Hacktoberfest 2026: những issue maintainer đã đánh dấu cho tháng Mười, đang mở và phù hợp người mới. Xem issue Hacktoberfest

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

Đã đóng Phù hợp với người mới
#66,295 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

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
Loại issue
Tái cấu trúc
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
github-actions, go
Lĩnh vực
security, tooling

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ả

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
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

Mở trong Codespaces

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.

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. 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.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của github/gh-aw

Tất cả issue của github/gh-aw

Issue tương tự

Thêm issue về Go

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.