Use COMMENT actions on PR Reviews (#559)

Signed-off-by: Glenn Jocher <[email protected]>
Co-authored-by: UltralyticsAssistant <[email protected]>
This commit is contained in:
Glenn Jocher
2025-10-19 18:19:26 +02:00
committed by GitHub
co-authored by UltralyticsAssistant
parent adf08baa79
commit 6761e47738
4 changed files with 9 additions and 11 deletions
+1 -1
View File
@@ -94,7 +94,7 @@ runs:
INPUTS_SPELLING: ${{ inputs.spelling }}
run: |
# For debug
# sudo env "PATH=$PATH" uv pip install --system --break-system-packages git+https://github.com/ultralytics/actions@update codespell tomli
# sudo env "PATH=$PATH" uv pip install --system --break-system-packages git+https://github.com/ultralytics/actions@main codespell tomli
packages="ultralytics-actions"
if [ "$INPUTS_SPELLING" = "true" ]; then
packages="$packages codespell tomli"
+1 -1
View File
@@ -23,4 +23,4 @@
# ├── test_summarize_pr.py
# └── ...
__version__ = "0.1.1"
__version__ = "0.1.2"
+3 -5
View File
@@ -90,7 +90,7 @@ def generate_pr_review(repository: str, diff_text: str, pr_title: str, pr_descri
content = (
"You are an expert code reviewer for Ultralytics. Provide detailed inline comments on specific code changes.\n\n"
"Focus on: Code quality, style, best practices, bugs, edge cases, error handling, performance, security, documentation, test coverage\n\n"
"FORMATTING: Use backticks for code, file names, branch names, function names, variable names, packages\n\n"
"FORMATTING: Use backticks for all summary and suggestion code, files, branches, functions, variables, packages, e.g. `x=3`\n\n"
"CRITICAL RULES:\n"
"1. Quality over quantity: Zero comments is fine for clean code - only flag truly important issues\n"
f"2. {comment_guidance} - these are maximums, not targets\n"
@@ -113,7 +113,7 @@ def generate_pr_review(repository: str, diff_text: str, pr_title: str, pr_descri
"- Suggestions replace ONLY the single line at 'line' - for multi-line fixes, describe the change in 'message' instead\n"
"- Do NOT provide 'start_line' when including a 'suggestion' - suggestions are always single-line only\n"
"- Suggestion content must match the exact indentation of the original line\n"
"- Never include triple backticks (```) in suggestions as they break markdown formatting\n"
"- Avoid triple backticks (```) in suggestions as they break markdown formatting\n"
"- It's better to flag an issue without a suggestion than provide a wrong or uncertain fix\n\n"
"Return JSON: "
'{"comments": [{"file": "exact/path", "line": N, "severity": "HIGH", "message": "...", "suggestion": "..."}], "summary": "..."}\n\n'
@@ -236,9 +236,7 @@ def post_review_summary(event: Action, review_data: dict, review_number: int) ->
review_title = f"{REVIEW_MARKER} {review_number}" if review_number > 1 else REVIEW_MARKER
comments = review_data.get("comments", [])
event_type = (
"REQUEST_CHANGES" if any(c.get("severity") not in ["LOW", "SUGGESTION", None] for c in comments) else "APPROVE"
)
event_type = "COMMENT" if any(c.get("severity") not in ["LOW", "SUGGESTION", None] for c in comments) else "APPROVE"
body = (
f"## {review_title}\n\n"
+4 -4
View File
@@ -19,7 +19,7 @@ def get_release_diff(event, previous_tag: str, latest_tag: str) -> str:
"""Retrieves the differences between two specified Git tags in a GitHub repository."""
url = f"{GITHUB_API_URL}/repos/{event.repository}/compare/{previous_tag}...{latest_tag}"
r = event.get(url, headers=event.headers_diff)
return r.text if r.status_code == 200 else f"Failed to get diff: {r.content}"
return r.text if r.status_code == 200 else f"Failed to get diff: {r.text}"
def get_prs_between_tags(event, previous_tag: str, latest_tag: str) -> list:
@@ -42,8 +42,8 @@ def get_prs_between_tags(event, previous_tag: str, latest_tag: str) -> list:
pr_numbers.update(pr_matches)
prs = []
time.sleep(10) # Allow final PR summary to update on merge
for pr_number in sorted(pr_numbers): # earliest to latest
time.sleep(1) # Rate limit: GitHub search API has strict limits
pr_url = f"{GITHUB_API_URL}/repos/{event.repository}/pulls/{pr_number}"
pr_response = event.get(pr_url)
if pr_response.status_code == 200:
@@ -52,7 +52,7 @@ def get_prs_between_tags(event, previous_tag: str, latest_tag: str) -> list:
{
"number": pr_data["number"],
"title": pr_data["title"],
"body": remove_html_comments(pr_data["body"]),
"body": remove_html_comments(pr_data.get("body", "")),
"author": pr_data["user"]["login"],
"html_url": pr_data["html_url"],
"merged_at": pr_data["merged_at"],
@@ -140,7 +140,7 @@ def generate_release_summary(
},
{
"role": "user",
"content": f"Summarize the updates made in the '{latest_tag}' tag, focusing on major model or features changes, their purpose, and potential impact. Keep the summary clear and suitable for a broad audience. Add emojis to enliven the summary. Prioritize changes from the current PR (the first in the list), which is usually the most important in the release. Reply directly with a summary along these example guidelines, though feel free to adjust as appropriate:\n\n"
"content": f"Summarize the updates made in the '{latest_tag}' tag, focusing on major model or features changes, their purpose, and potential impact. Keep the summary clear and suitable for a broad audience. Add emojis to enliven the summary. Prioritize changes from the current PR (the last in the list), which is usually the most important in the release. Reply directly with a summary along these example guidelines, though feel free to adjust as appropriate:\n\n"
f"## 🌟 Summary (single-line synopsis)\n"
f"## 📊 Key Changes (bullet points highlighting any major changes)\n"
f"## 🎯 Purpose & Impact (bullet points explaining any benefits and potential impact to users)\n\n\n"