-
-
Notifications
You must be signed in to change notification settings - Fork 50.5k
feat: add automated bug triage utility (#14561) #14611
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Yeeyash
wants to merge
5
commits into
TheAlgorithms:master
Choose a base branch
from
Yeeyash:main
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+282
−0
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
290e24c
feat: add automated bug triage utility
Yeeyash 934e6f4
made doctests capable
Yeeyash 1136d12
Edit: classify_severity doctests capable
Yeeyash d1ffd53
Changes for Ruff and Timezone awareness
Yeeyash 986aff3
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,141 @@ | ||
| """ | ||
| Automated Bug Triage Tool | ||
| This script scans markdown bug reports, classifies them by severity based on | ||
| keywords, and generates a summarized triage report in Markdown format. | ||
| """ | ||
|
|
||
| import glob | ||
| import os | ||
| from datetime import datetime, UTC | ||
| from pathlib import Path | ||
|
|
||
| # Configuration: Adjust these paths based on your local environment | ||
| BASE_DIR = Path(__file__).parent | ||
| BUG_PATH = str(BASE_DIR / "production" / "qa" / "bugs" / "*.md") | ||
| OUTPUT_PATH = str(BASE_DIR / "production" / "qa") | ||
|
|
||
|
|
||
| def classify_severity(content: str) -> str: | ||
| """ | ||
| Classifies bug severity based on specific keywords found in the content. | ||
| Returns S1 (Critical) through S4 (Minor). | ||
| >>> classify_severity("The application had a fatal crash on startup.") | ||
| 'S1' | ||
| >>> classify_severity("The UI is a bit slow today.") | ||
| 'S3' | ||
| """ | ||
| content = content.lower() | ||
| if any(k in content for k in ["crash", "data loss", "cannot start", "fatal"]): | ||
| return "S1" | ||
| if any(k in content for k in ["broken", "not working", "fail"]): | ||
| return "S2" | ||
| if any(k in content for k in ["slow", "incorrect", "glitch"]): | ||
| return "S3" | ||
| return "S4" | ||
|
|
||
|
|
||
| def classify_priority(severity: str) -> str: | ||
| """ | ||
| Maps the technical severity level to a business priority level. | ||
| >>> classify_priority("S1") | ||
| 'P1' | ||
| >>> classify_priority("S4") | ||
| 'P4' | ||
| """ | ||
| priority_map = {"S1": "P1", "S2": "P2", "S3": "P3"} | ||
| return priority_map.get(severity, "P4") | ||
|
|
||
|
|
||
| def read_bugs() -> list[dict]: | ||
| """ | ||
| Reads all markdown files in the BUG_PATH and extracts metadata. | ||
| >>> read_bugs() | ||
| [] | ||
| """ | ||
| files = glob.glob(BUG_PATH) | ||
| bugs = [] | ||
|
|
||
| for i, file_path in enumerate(sorted(files)): | ||
| try: | ||
| with open(file_path, encoding="utf-8") as f: | ||
| content = f.read() | ||
|
|
||
| severity = classify_severity(content) | ||
| priority = classify_priority(severity) | ||
|
|
||
| bugs.append( | ||
| { | ||
| "id": f"BUG-{i + 1:03}", | ||
| "file": file_path, | ||
| "severity": severity, | ||
| "priority": priority, | ||
| "summary": content.strip().split("\n")[0][:80], | ||
| } | ||
| ) | ||
| except OSError as e: | ||
| print(f"⚠️ Could not read file {file_path}: {e}") | ||
|
|
||
| return bugs | ||
|
|
||
|
|
||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As there is no test file in this pull request nor any test function or class in the file |
||
| def generate_report(bugs: list[dict]) -> None: | ||
| """ | ||
| Groups bugs by priority and writes a summarized Markdown report. | ||
| >>> generate_report([]) | ||
| ❌ No bugs to report. | ||
| """ | ||
| if not bugs: | ||
| print("❌ No bugs to report.") | ||
| return | ||
|
|
||
| date = datetime.now(UTC).strftime("%Y-%m-%d") | ||
|
|
||
| if not os.path.exists(OUTPUT_PATH): | ||
| os.makedirs(OUTPUT_PATH) | ||
|
|
||
| output_file = os.path.join(OUTPUT_PATH, f"bug-triage-{date}.md") | ||
|
|
||
| p1 = [b for b in bugs if b["priority"] == "P1"] | ||
| p2 = [b for b in bugs if b["priority"] == "P2"] | ||
| p3 = [b for b in bugs if b["priority"] == "P3"] | ||
| p4 = [b for b in bugs if b["priority"] == "P4"] | ||
|
|
||
| report_content = [ | ||
| "# Bug Triage Report", | ||
| f"**Date**: {date} ", | ||
| f"**Open bugs processed**: {len(bugs)}", | ||
| "\n---\n", | ||
| "## Triage Summary\n", | ||
| "| Priority | Count |", | ||
| "|----------|-------|", | ||
| f"| P1 | {len(p1)} |", | ||
| f"| P2 | {len(p2)} |", | ||
| f"| P3 | {len(p3)} |", | ||
| f"| P4 | {len(p4)} |", | ||
| "\n---\n", | ||
| "## P1 Bugs (Critical)", | ||
| ] | ||
|
|
||
| for b in p1: | ||
| report_content.append(f"- {b['id']} | {b['severity']} | {b['summary']}") | ||
|
|
||
| report_content.append("\n## P2 Bugs (High)") | ||
| for b in p2: | ||
| report_content.append(f"- {b['id']} | {b['severity']} | {b['summary']}") | ||
|
|
||
| report_content.append("\n## Backlog (P3/P4)") | ||
| for b in p3 + p4: | ||
| report_content.append(f"- {b['id']} | {b['severity']} | {b['summary']}") | ||
|
|
||
| with open(output_file, "w", encoding="utf-8") as f: | ||
| f.write("\n".join(report_content)) | ||
|
|
||
| print(f"✅ Report successfully generated at: {output_file}") | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| import doctest | ||
|
|
||
| doctest.testmod() | ||
| extracted_bugs = read_bugs() | ||
| generate_report(extracted_bugs) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,141 @@ | ||
| """ | ||
| Automated Bug Triage Tool | ||
| This script scans markdown bug reports, classifies them by severity based on | ||
| keywords, and generates a summarized triage report in Markdown format. | ||
| """ | ||
|
|
||
| import glob | ||
| import os | ||
| from datetime import UTC, datetime | ||
| from pathlib import Path | ||
|
|
||
| # Configuration: Adjust these paths based on your local environment | ||
| BASE_DIR = Path(__file__).parent | ||
| BUG_PATH = str(BASE_DIR / "production" / "qa" / "bugs" / "*.md") | ||
| OUTPUT_PATH = str(BASE_DIR / "production" / "qa") | ||
|
|
||
|
|
||
| def classify_severity(content: str) -> str: | ||
| """ | ||
| Classifies bug severity based on specific keywords found in the content. | ||
| Returns S1 (Critical) through S4 (Minor). | ||
| >>> classify_severity("The application had a fatal crash on startup.") | ||
| 'S1' | ||
| >>> classify_severity("The UI is a bit slow today.") | ||
| 'S3' | ||
| """ | ||
| content = content.lower() | ||
| if any(k in content for k in ["crash", "data loss", "cannot start", "fatal"]): | ||
| return "S1" | ||
| if any(k in content for k in ["broken", "not working", "fail"]): | ||
| return "S2" | ||
| if any(k in content for k in ["slow", "incorrect", "glitch"]): | ||
| return "S3" | ||
| return "S4" | ||
|
|
||
|
|
||
| def classify_priority(severity: str) -> str: | ||
| """ | ||
| Maps the technical severity level to a business priority level. | ||
| >>> classify_priority("S1") | ||
| 'P1' | ||
| >>> classify_priority("S4") | ||
| 'P4' | ||
| """ | ||
| priority_map = {"S1": "P1", "S2": "P2", "S3": "P3"} | ||
| return priority_map.get(severity, "P4") | ||
|
|
||
|
|
||
| def read_bugs() -> list[dict]: | ||
| """ | ||
| Reads all markdown files in the BUG_PATH and extracts metadata. | ||
| >>> read_bugs() | ||
| [] | ||
| """ | ||
| files = glob.glob(BUG_PATH) | ||
| bugs = [] | ||
|
|
||
| for i, file_path in enumerate(sorted(files)): | ||
| try: | ||
| with open(file_path, encoding="utf-8") as f: | ||
| content = f.read() | ||
|
|
||
| severity = classify_severity(content) | ||
| priority = classify_priority(severity) | ||
|
|
||
| bugs.append( | ||
| { | ||
| "id": f"BUG-{i + 1:03}", | ||
| "file": file_path, | ||
| "severity": severity, | ||
| "priority": priority, | ||
| "summary": content.strip().split("\n")[0][:80], | ||
| } | ||
| ) | ||
| except OSError as e: | ||
| print(f"⚠️ Could not read file {file_path}: {e}") | ||
|
|
||
| return bugs | ||
|
|
||
|
|
||
| def generate_report(bugs: list[dict]) -> None: | ||
| """ | ||
| Groups bugs by priority and writes a summarized Markdown report. | ||
| >>> generate_report([]) | ||
| ❌ No bugs to report. | ||
| """ | ||
| if not bugs: | ||
| print("❌ No bugs to report.") | ||
| return | ||
|
|
||
| date = datetime.now(UTC).strftime("%Y-%m-%d") | ||
|
|
||
| if not os.path.exists(OUTPUT_PATH): | ||
| os.makedirs(OUTPUT_PATH) | ||
|
|
||
| output_file = os.path.join(OUTPUT_PATH, f"bug-triage-{date}.md") | ||
|
|
||
| p1 = [b for b in bugs if b["priority"] == "P1"] | ||
| p2 = [b for b in bugs if b["priority"] == "P2"] | ||
| p3 = [b for b in bugs if b["priority"] == "P3"] | ||
| p4 = [b for b in bugs if b["priority"] == "P4"] | ||
|
|
||
| report_content = [ | ||
| "# Bug Triage Report", | ||
| f"**Date**: {date} ", | ||
| f"**Open bugs processed**: {len(bugs)}", | ||
| "\n---\n", | ||
| "## Triage Summary\n", | ||
| "| Priority | Count |", | ||
| "|----------|-------|", | ||
| f"| P1 | {len(p1)} |", | ||
| f"| P2 | {len(p2)} |", | ||
| f"| P3 | {len(p3)} |", | ||
| f"| P4 | {len(p4)} |", | ||
| "\n---\n", | ||
| "## P1 Bugs (Critical)", | ||
| ] | ||
|
|
||
| for b in p1: | ||
| report_content.append(f"- {b['id']} | {b['severity']} | {b['summary']}") | ||
|
|
||
| report_content.append("\n## P2 Bugs (High)") | ||
| for b in p2: | ||
| report_content.append(f"- {b['id']} | {b['severity']} | {b['summary']}") | ||
|
|
||
| report_content.append("\n## Backlog (P3/P4)") | ||
| for b in p3 + p4: | ||
| report_content.append(f"- {b['id']} | {b['severity']} | {b['summary']}") | ||
|
|
||
| with open(output_file, "w", encoding="utf-8") as f: | ||
| f.write("\n".join(report_content)) | ||
|
|
||
| print(f"✅ Report successfully generated at: {output_file}") | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| import doctest | ||
|
|
||
| doctest.testmod() | ||
| extracted_bugs = read_bugs() | ||
| generate_report(extracted_bugs) | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 functionread_bugs