fix(description): use regex for minute suffix replacement instead of blanket .replace#2318
fix(description): use regex for minute suffix replacement instead of blanket .replace#2318
Conversation
…blanket .replace
The `.replace('m', ' minutes')` call in the contribution time estimate
rendering replaced ALL occurrences of the letter 'm' in any string, not
just the time suffix. For example, "30m implementation" would become
"30 minutes i minutes ple minutes entation".
Replace with `re.sub(r'(\d+)m\b', r'\1 minutes', ...)` which only
matches 'm' immediately following digits at a word boundary.
Review Summary by QodoFix minute suffix replacement using regex pattern matching
WalkthroughsDescription• Replace blanket .replace('m', ' minutes') with regex pattern
• Fixes incorrect replacement of all 'm' letters in strings
• Uses re.sub(r'(\d+)m\b', r'\1 minutes', ...) for precise matching
• Applied to both GFM and non-GFM contribution time estimate paths
Diagramflowchart LR
A["Contribution time estimate<br/>with 'm' suffix"] -->|Old: .replace| B["All 'm' letters<br/>replaced incorrectly"]
A -->|New: re.sub| C["Only time suffix<br/>'m' replaced correctly"]
File Changes1. pr_agent/algo/utils.py
|
Code Review by Qodo
|
Address review feedback on PR #2318: - Extract inline re.sub calls into _expand_minute_suffix() helper to keep lines under 120 chars - Add TestExpandMinuteSuffix with 4 test cases: standalone "30m", partial-unit "30ms", "30m" before space, and compound "2h 30m" Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
|
Persistent review updated to latest commit 69d8ff6 |
Summary
.replace('m', ' minutes')in the contribution time estimate rendering replaced every occurrence of the lettermin the string, not just the time suffix. For example,"30m implementation"became"30 minutes i minutes ple minutes entation".re.sub(r'(\d+)m\b', r'\1 minutes', ...)which only targetsmimmediately following one or more digits at a word boundary (e.g.30m->30 minutes), leaving the rest of the string intact.remodule was already imported in this file, so no new imports are needed.Bug reproduction
Test plan
"30m","30m implementation","1h 30m","medium complexity"(unchanged),"45m","2h"(unchanged)