From 506b366fe2974c866e3d3663800636deeec3818c Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Fri, 5 Jun 2026 22:49:03 +0200 Subject: [PATCH] Improve docs, comments, and correctness (#761) --- .github/ISSUE_TEMPLATE/bug-report.yml | 1 + .github/ISSUE_TEMPLATE/feature-request.yml | 1 + .github/ISSUE_TEMPLATE/question.yml | 1 + README.md | 10 ++++------ README.zh-CN.md | 7 +++---- action.yml | 6 +----- actions/__init__.py | 2 +- actions/summarize_pr.py | 12 +++++++++++- actions/utils/openai_utils.py | 2 +- dependabot/README.md | 2 +- tests/test_summarize_pr.py | 21 +++++++++++++-------- 11 files changed, 38 insertions(+), 27 deletions(-) diff --git a/.github/ISSUE_TEMPLATE/bug-report.yml b/.github/ISSUE_TEMPLATE/bug-report.yml index 503db1f..8ded494 100644 --- a/.github/ISSUE_TEMPLATE/bug-report.yml +++ b/.github/ISSUE_TEMPLATE/bug-report.yml @@ -32,6 +32,7 @@ body: - "Retry Action" - "Cleanup Disk Action" - "Scan PRs Action" + - "Dependabot Action" - "Python package (`ultralytics-actions`)" - "Repository documentation / README" - "Other" diff --git a/.github/ISSUE_TEMPLATE/feature-request.yml b/.github/ISSUE_TEMPLATE/feature-request.yml index 90d60b7..a4672c7 100644 --- a/.github/ISSUE_TEMPLATE/feature-request.yml +++ b/.github/ISSUE_TEMPLATE/feature-request.yml @@ -32,6 +32,7 @@ body: - "Retry Action" - "Cleanup Disk Action" - "Scan PRs Action" + - "Dependabot Action" - "Python package (`ultralytics-actions`)" - "Repository documentation / README" - "Other" diff --git a/.github/ISSUE_TEMPLATE/question.yml b/.github/ISSUE_TEMPLATE/question.yml index 3bb3370..55501a5 100644 --- a/.github/ISSUE_TEMPLATE/question.yml +++ b/.github/ISSUE_TEMPLATE/question.yml @@ -30,6 +30,7 @@ body: - "Retry Action" - "Cleanup Disk Action" - "Scan PRs Action" + - "Dependabot Action" - "Python package (`ultralytics-actions`)" - "Repository documentation / README" - "Other" diff --git a/README.md b/README.md index 9cee763..dd01dc1 100644 --- a/README.md +++ b/README.md @@ -27,7 +27,7 @@ This repository provides three main components: ## Ultralytics Actions (Main Action) -AI-powered formatting, labeling, and PR summaries for Python, Swift, and Markdown files. +AI-powered formatting, labeling, and PR summaries for Python, Swift, Dart, and Markdown files. ### 📄 Features @@ -98,7 +98,7 @@ jobs: with: token: ${{ secrets.GITHUB_TOKEN }} # Auto-generated token labels: true # Auto-label issues/PRs using AI - python-version: "3.13" # Optional: set up a specific Python version + python-version: "3.14" # Optional: set up a specific Python version python: true # Format Python with Ruff python_docstrings: true # Format Python docstrings (default: true) biome: true # Format JS/TS with Biome (auto-detected via biome.json) @@ -172,11 +172,9 @@ Update GitHub Actions versions across organization repositories with cached rele ## Python Package -Install `ultralytics-actions` for programmatic access to action utilities. +Install the `ultralytics-actions` package for programmatic access to action utilities, including all [requirements](https://github.com/ultralytics/actions/blob/main/pyproject.toml), in a [**Python>=3.8**](https://www.python.org/) environment. -[![PyPI - Version](https://img.shields.io/pypi/v/ultralytics-actions?logo=pypi&logoColor=white)](https://pypi.org/project/ultralytics-actions/) -[![Ultralytics Downloads](https://static.pepy.tech/badge/ultralytics-actions)](https://clickpy.clickhouse.com/dashboard/ultralytics-actions) -[![PyPI - Python Version](https://img.shields.io/pypi/pyversions/ultralytics-actions?logo=python&logoColor=gold)](https://pypi.org/project/ultralytics-actions/) +[![PyPI - Version](https://img.shields.io/pypi/v/ultralytics-actions?logo=pypi&logoColor=white)](https://pypi.org/project/ultralytics-actions/) [![Ultralytics Downloads](https://static.pepy.tech/badge/ultralytics-actions)](https://clickpy.clickhouse.com/dashboard/ultralytics-actions) [![PyPI - Python Version](https://img.shields.io/pypi/pyversions/ultralytics-actions?logo=python&logoColor=gold)](https://pypi.org/project/ultralytics-actions/) ```bash pip install ultralytics-actions diff --git a/README.zh-CN.md b/README.zh-CN.md index 5b766f7..5bc607c 100644 --- a/README.zh-CN.md +++ b/README.zh-CN.md @@ -98,6 +98,7 @@ jobs: with: token: ${{ secrets.GITHUB_TOKEN }} # Auto-generated token labels: true # Auto-label issues/PRs using AI + python-version: "3.14" # Optional: set up a specific Python version python: true # Format Python with Ruff python_docstrings: true # Format Python docstrings (default: true) biome: true # Format JS/TS with Biome (auto-detected via biome.json) @@ -171,11 +172,9 @@ jobs: ## Python 包 -安装 `ultralytics-actions` 以便通过代码使用 action 工具。 +在 [**Python>=3.8**](https://www.python.org/) 环境中安装 `ultralytics-actions` 包及其全部[依赖项](https://github.com/ultralytics/actions/blob/main/pyproject.toml),以便通过代码使用 action 工具。 -[![PyPI - Version](https://img.shields.io/pypi/v/ultralytics-actions?logo=pypi&logoColor=white)](https://pypi.org/project/ultralytics-actions/) -[![Ultralytics Downloads](https://static.pepy.tech/badge/ultralytics-actions)](https://clickpy.clickhouse.com/dashboard/ultralytics-actions) -[![PyPI - Python Version](https://img.shields.io/pypi/pyversions/ultralytics-actions?logo=python&logoColor=gold)](https://pypi.org/project/ultralytics-actions/) +[![PyPI - Version](https://img.shields.io/pypi/v/ultralytics-actions?logo=pypi&logoColor=white)](https://pypi.org/project/ultralytics-actions/) [![Ultralytics Downloads](https://static.pepy.tech/badge/ultralytics-actions)](https://clickpy.clickhouse.com/dashboard/ultralytics-actions) [![PyPI - Python Version](https://img.shields.io/pypi/pyversions/ultralytics-actions?logo=python&logoColor=gold)](https://pypi.org/project/ultralytics-actions/) ```bash pip install ultralytics-actions diff --git a/action.yml b/action.yml index 0ed4d68..3de871b 100644 --- a/action.yml +++ b/action.yml @@ -84,9 +84,6 @@ inputs: first_issue_response: description: "Example response to a new issue" required: false - first_pr_response: - description: "Example response to a new PR" - required: false bun_update: description: "Run bun update to update bun.lock if bun project detected" required: false @@ -269,7 +266,7 @@ runs: codespell \ --builtin clear,rare,informal,en-GB_to_en-US \ --write-changes \ - --uri-ignore-words-list * \ + --uri-ignore-words-list "*" \ --ignore-regex '\b[a-z]+[A-Z][a-zA-Z]*\b' \ --ignore-words-list "nin,cancelled,MapPin,couldn,grey,writeable,RepResNet,Idenfy,WIT,Smoot,EHR,ROUGE,ALS,Carmel,FPR,Hach,Calle,ore,COO,MOT,crate,nd,ned,strack,dota,ane,segway,fo,gool,winn,commend,bloc,nam,afterall,skelton,goin,cann,CANN" \ --skip "*.pt,*.pth,*.torchscript,*.onnx,*.tflite,*.pb,*.bin,*.param,*.mlmodel,*.engine,*.npy,*.data*,*.csv,*pnnx*,*venv*,*translat*,*lock*,__pycache__*,*.ico,*.jpg,*.png,*.webp,*.avif,*.mp4,*.mov,/runs,/.git,./docs/??/*.md,./docs/mkdocs_??.yml,action.yml" @@ -296,7 +293,6 @@ runs: env: GITHUB_TOKEN: ${{ inputs.token }} FIRST_ISSUE_RESPONSE: ${{ inputs.first_issue_response }} - FIRST_PR_RESPONSE: ${{ inputs.first_pr_response }} BRAVE_API_KEY: ${{ inputs.brave_api_key }} OPENAI_API_KEY: ${{ inputs.openai_api_key }} ANTHROPIC_API_KEY: ${{ inputs.anthropic_api_key }} diff --git a/actions/__init__.py b/actions/__init__.py index c458853..9fd45dd 100644 --- a/actions/__init__.py +++ b/actions/__init__.py @@ -29,4 +29,4 @@ # ├── test_summarize_pr.py # └── ... -__version__ = "0.2.15" +__version__ = "0.2.16" diff --git a/actions/summarize_pr.py b/actions/summarize_pr.py index 2a89765..43d3303 100644 --- a/actions/summarize_pr.py +++ b/actions/summarize_pr.py @@ -2,6 +2,8 @@ from __future__ import annotations +from urllib.parse import urlparse + from .utils import ( ACTIONS_CREDIT, GITHUB_API_URL, @@ -41,7 +43,15 @@ def generate_merge_message(pr_summary, pr_credit, pr_url): def generate_issue_comment(pr_url, pr_summary, pr_credit, pr_title=""): """Generates personalized issue comment based on PR context.""" - repo_parts = pr_url.split("/repos/")[1].split("/pulls/")[0] if "/repos/" in pr_url else "" + # pr_url is the GraphQL PullRequest.url HTML URL (https://github.com/owner/repo/pull/N) in production; + # REST API URLs (https://api.github.com/repos/owner/repo/pulls/N) are also supported + parsed = urlparse(pr_url) + if "/repos/" in pr_url and "/pulls/" in pr_url: + repo_parts = pr_url.split("/repos/", 1)[1].split("/pulls/", 1)[0] + elif parsed.hostname == "github.com" and "/pull/" in parsed.path: + repo_parts = parsed.path.lstrip("/").split("/pull/", 1)[0] + else: + repo_parts = "" owner_repo = repo_parts.split("/") repo_name = owner_repo[-1] if len(owner_repo) > 1 else "package" diff --git a/actions/utils/openai_utils.py b/actions/utils/openai_utils.py index bde7c25..43e0908 100644 --- a/actions/utils/openai_utils.py +++ b/actions/utils/openai_utils.py @@ -235,7 +235,7 @@ def get_response( } if system_content: data["system"] = system_content - # Skip web_search for Anthropic when using JSON schema (causes empty responses) + # Tools (web_search) are not forwarded to Anthropic (caused empty responses with JSON schema) # Handle structured JSON output for Anthropic if text_format and text_format.get("format", {}).get("type") == "json_schema": schema = text_format["format"].get("schema", {}) diff --git a/dependabot/README.md b/dependabot/README.md index 706a90c..f98a181 100644 --- a/dependabot/README.md +++ b/dependabot/README.md @@ -33,7 +33,7 @@ jobs: ## How It Works 1. Lists all active repos in the org (filtered by visibility) -2. Fetches workflow files (`.github/workflows/*.yml` and `action.yml`) from each repo +2. Fetches GitHub Actions files (`.github/workflows/*.yml`/`*.yaml` and `action.yml`/`action.yaml`) from each repo 3. Parses `uses:` lines and resolves the latest release for each action 4. Creates one PR per outdated action per repo, updating all files that reference it 5. Skips PRs that already exist (matches by title) diff --git a/tests/test_summarize_pr.py b/tests/test_summarize_pr.py index b77cb91..751a4e2 100644 --- a/tests/test_summarize_pr.py +++ b/tests/test_summarize_pr.py @@ -34,12 +34,17 @@ def test_generate_issue_comment(mock_get_response): """Test generating issue comments about PR fixes.""" mock_get_response.return_value = "This issue is fixed in PR #123" - comment = generate_issue_comment( - pr_url="https://api.github.com/repos/owner/repo/pulls/123", - pr_summary="Fixed bug", - pr_credit="@testuser", - pr_title="Bug fix PR", - ) + for pr_url in ("https://github.com/owner/repo/pull/123", "https://api.github.com/repos/owner/repo/pulls/123"): + comment = generate_issue_comment( + pr_url=pr_url, + pr_summary="Fixed bug", + pr_credit="@testuser", + pr_title="Bug fix PR", + ) - assert comment == "This issue is fixed in PR #123" - mock_get_response.assert_called_once() + assert comment == "This issue is fixed in PR #123" + prompt = mock_get_response.call_args[0][0][1]["content"] + assert "pip install -U repo>=VERSION" in prompt + assert "pip install git+https://github.com/owner/repo.git@main" in prompt + + assert mock_get_response.call_count == 2