fix: use word boundaries for issue label matching#55
Conversation
labelMatchesAny was using String.includes() to match labels against keyword sets, causing false positives on substrings. A label like "debug" matched keyword "bug", "docker" matched "doc", and "prefix" matched "fix", misclassifying issues in the type quota system. Switched to a single pre-compiled regex with \b word boundaries per keyword set (cached via WeakMap). Emoji-prefixed labels like ":lady_beetle: bug" still match correctly since \b triggers at the colon/space boundary.
📝 WalkthroughWalkthroughThe changes refactor label matching logic in issue handling to use word-boundary regex patterns instead of substring matching, improving accuracy for keyword identification. The Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
🚥 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)
Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
test/unit/issues.test.ts (1)
20-23: Verify emoji shortcode matching is intentional behavior.Line 22 tests that
:bug: reportmatches the keywordbug. This works because the colons in:bug:create word boundaries, causing "bug" inside the shortcode to match. If the intent is only to match labels like:lady_beetle: bug(emoji followed by keyword), the current regex would also match shortcodes that happen to contain keywords (e.g.,:bug:,:firefix:would match "fix").If this is the desired behavior, consider adding a brief comment in the test explaining that emoji shortcodes containing keywords are intentionally matched.
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@test/unit/issues.test.ts` around lines 20 - 23, Test currently asserts that labelMatchesAny(':bug: report', BUG_KEYWORDS) returns true because the regex treats colons as word boundaries and matches "bug" inside an emoji shortcode; to address the review, either (preferred) add a short inline comment above the test case explaining that emoji shortcodes containing keywords (e.g., ':bug:') are intentionally considered matches for labelMatchesAny against BUG_KEYWORDS, or (if unintended) update the matching logic in labelMatchesAny to ignore text inside colon-delimited shortcodes (i.e., skip or strip /:[^:]+:/ sequences before applying BUG_KEYWORDS) so ':bug:' no longer triggers a match.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@test/unit/issues.test.ts`:
- Around line 20-23: Test currently asserts that labelMatchesAny(':bug: report',
BUG_KEYWORDS) returns true because the regex treats colons as word boundaries
and matches "bug" inside an emoji shortcode; to address the review, either
(preferred) add a short inline comment above the test case explaining that emoji
shortcodes containing keywords (e.g., ':bug:') are intentionally considered
matches for labelMatchesAny against BUG_KEYWORDS, or (if unintended) update the
matching logic in labelMatchesAny to ignore text inside colon-delimited
shortcodes (i.e., skip or strip /:[^:]+:/ sequences before applying
BUG_KEYWORDS) so ':bug:' no longer triggers a match.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 658e565b-e837-4bf9-a526-2685f3483c6e
📒 Files selected for processing (2)
src/sources/issues.tstest/unit/issues.test.ts
|
Nice one |
labelMatchesAnywas usingString.includes()to check if a label contained a keyword, which caused substring false positives. Labels likedebugmatched keywordbug,dockermatcheddoc,prefixmatchedfix- all getting misclassified in the type quota system and stealing slots from actual bugs/docs issues.Switched to a single pre-compiled regex with
\bword boundaries per keyword set (cached via WeakMap so sets that don't change only compile once). Emoji-prefixed labels like:lady_beetle: bugstill match correctly since\btriggers at the colon/space boundary.Added 15 unit tests covering the edge cases.
Summary by CodeRabbit
Bug Fixes
Tests