feat: add automated bug triage utility (#14561)#14611
feat: add automated bug triage utility (#14561)#14611Yeeyash wants to merge 6 commits intoTheAlgorithms:masterfrom
Conversation
There was a problem hiding this comment.
Click here to look at the relevant links ⬇️
🔗 Relevant Links
Repository:
Python:
Automated review generated by algorithms-keeper. If there's any problem regarding this review, please open an issue about it.
algorithms-keeper commands and options
algorithms-keeper actions can be triggered by commenting on this PR:
@algorithms-keeper reviewto trigger the checks for only added pull request files@algorithms-keeper review-allto trigger the checks for all the pull request files, including the modified files. As we cannot post review comments on lines not part of the diff, this command will post all the messages in one comment.NOTE: Commands are in beta and so this feature is restricted only to a member or owner of the organization.
| "S2": "P2", | ||
| "S3": "P3" | ||
| } | ||
| return priority_map.get(severity, "P4") |
There was a problem hiding this comment.
As there is no test file in this pull request nor any test function or class in the file bug_triage.py, please provide doctest for the function read_bugs
|
|
||
| return bugs | ||
|
|
||
|
|
There was a problem hiding this comment.
As there is no test file in this pull request nor any test function or class in the file bug_triage.py, please provide doctest for the function generate_report
c356ce0 to
d1ffd53
Compare
for more information, see https://pre-commit.ci
| 'S3' | ||
| """ | ||
| content = content.lower() | ||
| if any(k in content for k in ["crash", "data loss", "cannot start", "fatal"]): |
There was a problem hiding this comment.
The keyword-based severity classification works but is fragile —
hardcoded keyword lists are easy to miss edge cases and difficult
to maintain. Consider extracting them as module-level constants
for easier updates:
SEVERITY_KEYWORDS = {
"S1": ["crash", "data loss", "cannot start", "fatal"],
"S2": ["broken", "not working", "fail"],
"S3": ["slow", "incorrect", "glitch"],
}
This makes it trivial to add/remove keywords without touching
the function logic.
| "summary": content.strip().split("\n")[0][:80], | ||
| } | ||
| ) | ||
| except OSError as e: |
There was a problem hiding this comment.
Good use of OSError for file reading failures. However using
print() for error reporting inside a library function is not
ideal — it mixes concerns and makes testing harder.
Consider using the logging module instead:
import logging
logger = logging.getLogger(name)
logger.warning("Could not read file %s: %s", file_path, e)
This allows callers to control log levels and output destinations.
|
|
||
| output_file = os.path.join(OUTPUT_PATH, f"bug-triage-{date}.md") | ||
|
|
||
| p1 = [b for b in bugs if b["priority"] == "P1"] |
There was a problem hiding this comment.
Lines 98-101 create four separate list comprehensions iterating
over bugs four times. This can be simplified using a single pass
with a defaultdict or groupby:
from collections import defaultdict
grouped = defaultdict(list)
for b in bugs:
grouped[b["priority"]].append(b)
p1, p2, p3, p4 = grouped["P1"], grouped["P2"], grouped["P3"], grouped["P4"]
This reduces O(4n) to O(n) — more efficient for large bug lists.
Describe your change:
This PR adds a utility script bug_triage.py that automates the classification of bug reports based on severity keywords (e.g., "crash", "slow"). It provides a structured Markdown summary of open bugs categorized by priority.
Changes:
pathlibfor robustness.Wikipedia URL: https://en.wikipedia.org/wiki/Triage
Checklist: