From 6761e477384bb47ab419f0c5624d2148974f9f4f Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Sun, 19 Oct 2025 18:19:26 +0200 Subject: [PATCH] Use `COMMENT` actions on PR Reviews (#559) Signed-off-by: Glenn Jocher Co-authored-by: UltralyticsAssistant --- action.yml | 2 +- actions/__init__.py | 2 +- actions/review_pr.py | 8 +++----- actions/summarize_release.py | 8 ++++---- 4 files changed, 9 insertions(+), 11 deletions(-) diff --git a/action.yml b/action.yml index 72c7fc3..d9b6ed5 100644 --- a/action.yml +++ b/action.yml @@ -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" diff --git a/actions/__init__.py b/actions/__init__.py index 4fc3cd9..d924218 100644 --- a/actions/__init__.py +++ b/actions/__init__.py @@ -23,4 +23,4 @@ # ├── test_summarize_pr.py # └── ... -__version__ = "0.1.1" +__version__ = "0.1.2" diff --git a/actions/review_pr.py b/actions/review_pr.py index 006db26..1bae5a5 100644 --- a/actions/review_pr.py +++ b/actions/review_pr.py @@ -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" diff --git a/actions/summarize_release.py b/actions/summarize_release.py index 30042b7..beb7379 100644 --- a/actions/summarize_release.py +++ b/actions/summarize_release.py @@ -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"