fix: correct label parsing for hyphenated GitHub usernames#1061
fix: correct label parsing for hyphenated GitHub usernames#1061
Conversation
Label parsing used split("-")[-1] which broke GitHub usernames
containing hyphens (e.g., "Ahmad-Hafe" was parsed as "Hafe").
Fixed by using prefix-length slicing to extract the username
after the known label prefix. Also switched substring `in`
checks to `startswith` for stricter prefix matching.
Review Summary by QodoFix label parsing for hyphenated GitHub usernames
WalkthroughsDescription• Fixed label parsing for GitHub usernames containing hyphens
- Changed from split("-")[-1] to prefix-length slicing
- Affected LGTM, approved, and changes-requested labels
• Replaced substring in checks with startswith for stricter prefix matching
• Added comprehensive tests for hyphenated usernames and prefix-only matching
Diagramflowchart LR
A["Label with hyphen<br/>lgtm-Ahmad-Hafe"] -->|Old: split by dash| B["Extracted only<br/>Hafe"]
A -->|New: prefix slicing| C["Extracted full<br/>Ahmad-Hafe"]
B --> D["Username not found<br/>in reviewers"]
C --> E["Username matched<br/>correctly"]
F["Substring in check<br/>lgtm in not-lgtm-user"] -->|Old: True| G["False positive"]
F -->|New: startswith| H["False negative<br/>prevented"]
File Changes1. webhook_server/libs/handlers/pull_request_handler.py
|
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: ASSERTIVE Plan: Pro Run ID: 📒 Files selected for processing (1)
WalkthroughRefactored label parsing in the pull request handler to use prefix-based matching ( Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Suggested labels
Suggested reviewers
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Code Review by Qodo🐞 Bugs (0) 📘 Rule violations (0) 📎 Requirement gaps (0)
Great, no issues found!Qodo reviewed your code and found no material issues that require reviewⓘ The new review experience is currently in Beta. Learn more |
|
Report bugs in Issues Welcome! 🎉This pull request will be automatically processed with the following features: 🔄 Automatic Actions
📋 Available CommandsPR Status Management
Review & Approval
Testing & Validation
Container Operations
Cherry-pick Operations
Label Management
✅ Merge RequirementsThis PR will be automatically approved when the following conditions are met:
📊 Review ProcessApprovers and ReviewersApprovers:
Reviewers:
Available Labels
AI Features
💡 Tips
For more information, please refer to the project documentation or contact the maintainers. |
|
/lgtm |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@webhook_server/tests/test_pull_request_handler.py`:
- Around line 1798-1814: The test is exercising the wrong code path:
approved-label parsing lives in _check_if_pr_approved, not
_check_labels_for_can_be_merged; update the
test_test_check_labels_for_can_be_merged_approved_label_only_matches_prefix to
call pull_request_handler._check_if_pr_approved (passing the same labels list)
and keep patching
pull_request_handler.owners_file_handler.all_pull_request_approvers to
["approver1"] and assertions unchanged so the test actually verifies that labels
starting with APPROVED_BY_LABEL_PREFIX match while labels containing the prefix
in the middle do not.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: ASSERTIVE
Plan: Pro
Run ID: af0876c9-bf72-47cc-850e-d8784676ca05
📒 Files selected for processing (2)
webhook_server/libs/handlers/pull_request_handler.pywebhook_server/tests/test_pull_request_handler.py
|
/build-and-push-container |
|
New container for ghcr.io/myk-org/github-webhook-server:pr-1061 published |
|
/verified |
|
/approve |
|
Successfully removed PR tag: ghcr.io/myk-org/github-webhook-server:pr-1061. |
|
New container for ghcr.io/myk-org/github-webhook-server:latest published |
Summary
split("-")[-1]which broke GitHub usernames containing hyphens (e.g.,Ahmad-Hafewas parsed asHafe), causing LGTM/approved/changes-requested labels to not be recognized_label[len(PREFIX):]) to correctly extract the full usernameinchecks tostartswithfor consistency with the prefix-based extraction and other patterns in the fileBug Details
The
can-be-mergedcheck counted only 1 LGTM instead of 2 when one reviewer had a hyphenated username. For example, labellgtm-Ahmad-Hafewas split as["lgtm", "Ahmad", "Hafe"]and only"Hafe"was extracted — which matched no reviewer.Affected all three label types:
lgtm-,approved-,changes-requested-.Bug existed since commit c90382a (2023-05-24).
Test plan
Summary by CodeRabbit
Bug Fixes
Tests