ci: add generic PR auto-review workflow (#21128)

- Add reusable PR review rules prompt

- Add workflow for automatic PR review on updates

- Remove unused similar_issues prompt file
This commit is contained in:
DIYgod 2026-02-12 21:24:13 +08:00 committed by GitHub
parent e43f570306
commit 7132127a5d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 146 additions and 46 deletions

50
.github/prompts/pr_review_rules.md vendored Normal file
View File

@ -0,0 +1,50 @@
# PR Review Rules for RSSHub
You are reviewing pull requests for RSSHub.
Only report **clear and actionable** violations in changed lines/files. Do not report speculative or uncertain issues.
## Route Metadata and Docs
1. `example` must start with `/` and be a working RSSHub route path.
2. Route name must not repeat namespace name.
3. In radar rules, `source` must be a relative host/path (no `https://`, no hash/query matching).
4. In radar rules, `target` must match the route path and declared params.
5. Namespace `url` should not include protocol prefix.
6. Use a single category in `categories`.
7. `parameters` keys must match real path parameters.
8. Keep route/docs lists in alphabetical order when touching sorted files.
9. Do not modify default values or working examples unless they are broken.
## Data Handling and Feed Quality
10. Use `ctx.cache.tryGet()` for detail fetching in loops; cache processed result instead of raw HTML.
11. `description` should contain article content only; do not duplicate `title`, `author`, `pubDate`, or tags.
12. Extract tags/categories into `category` field.
13. Use `parseDate()` for date fields when source provides time.
14. Do not set fake dates (`new Date()` fallback) when source has no valid time.
15. Keep each item `link` unique and human-readable (not raw API endpoint).
16. Do not trim/truncate title/content manually.
## API and Requesting
17. Prefer official API endpoints over scraping when available.
18. Fetch first page only; do not add custom pagination behavior.
19. Use common parameter `limit` instead of custom limit/query filtering.
20. Prefer path parameters over custom query parameters for route config.
21. Use RSSHub built-in UA behavior; avoid unnecessary hardcoded UA/Host unless required.
## Code Style and Maintainability
22. Use `camelCase` naming.
23. Use `import type { ... }` for type-only imports.
24. Keep imports sorted.
25. Use `art-template` for custom HTML rendering patterns used by RSSHub.
26. Avoid unnecessary changes outside PR scope.
## Reporting Format
- Report only violated rules.
- Each bullet should include: file path, problem, and concrete fix.
- Group repeated issues across files into one concise bullet when possible.
- If no rule is clearly violated, do not comment.

View File

@ -1,46 +0,0 @@
messages:
- role: system
content: |-
You are a GitHub assistant with access to GitHub Model Context Protocol (MCP)
tools in read-only mode. Your task is to search this repository's issues to find
previously filed issues similar to the provided issue title and body. Use the
GitHub tools via MCP to perform the search and retrieve real issue data (do not
fabricate results). Consider semantic similarity across title and body. Exclude
the current issue {{issue_number}}. Return up to 3 of the most similar past issues. If none are
reasonably similar, return an empty list. Output must follow the response schema
exactly and include only data you actually retrieved from GitHub tools.
The current GitHub repository is: "{{repository}}".
- role: user
content: |-
Find similar issues for issue {{issue_number}}:
Title: {{issue_title}}
Body:
{{issue_body}}
model: openai/gpt-4.1-mini
responseFormat: json_schema
jsonSchema: |-
{
"name": "similar_issues_result",
"strict": true,
"schema": {
"type": "object",
"properties": {
"matches": {
"type": "array",
"items": {
"type": "object",
"properties": {
"number": { "type": "integer" },
"title": { "type": "string" },
"url": { "type": "string" },
"similarity_score": { "type": "number", "minimum": 0, "maximum": 1 }
},
"required": ["number", "title", "url", "similarity_score"],
"additionalProperties": false
}
}
},
"required": ["matches"],
"additionalProperties": false
}
}

96
.github/workflows/pr-review.yml vendored Normal file
View File

@ -0,0 +1,96 @@
name: pr-review
on:
pull_request_target:
types: [opened, reopened, synchronize, ready_for_review]
workflow_dispatch:
inputs:
pr_number:
description: Pull request number to review manually
required: true
type: number
jobs:
review-pr:
if: github.event_name == 'workflow_dispatch' || github.event.pull_request.draft == false
runs-on: ubuntu-latest
timeout-minutes: 10
permissions:
contents: read
issues: write
pull-requests: write
steps:
- name: Checkout repository
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
- name: Set up Bun
uses: oven-sh/setup-bun@3d267786b128fe76c2f16a390aa2448b815359f3 # v2.1.2
- name: Install opencode
run: curl -fsSL https://opencode.ai/install | bash
- name: Review PR with rules
env:
OPENCODE_API_KEY: ${{ secrets.OPENCODE_API_KEY }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GITHUB_REPOSITORY: ${{ github.repository }}
PR_NUMBER: ${{ github.event.pull_request.number || inputs.pr_number }}
OPENCODE_PERMISSION: |
{
"bash": {
"*": "deny",
"gh auth*": "allow",
"gh pr*": "allow",
"gh api*": "allow"
},
"webfetch": "deny"
}
run: |
if [ -z "$PR_NUMBER" ]; then
echo "pr_number is required"
exit 1
fi
RULES=$(cat .github/prompts/pr_review_rules.md)
opencode run -m ${{ vars.OPENCODE_MODEL }} "A pull request has been created or updated in this repository.
Pull request number:
$PR_NUMBER
Repository:
$GITHUB_REPOSITORY
Your task:
1. Use GitHub CLI commands to inspect this PR's metadata and code changes.
2. Review only based on the following rules.
3. Report only clear and actionable violations from changed files.
4. If no clear violations are found, do not comment.
Review rules:
$RULES
Required behavior:
- Keep feedback concise and grouped by rule.
- Include file path and a concrete fix suggestion for each issue.
- Ignore uncertain or low-confidence findings.
- Avoid duplicate comments.
Comment protocol:
- Use marker: <!-- pr-auto-review -->
- Check existing comments in issue comments for this marker.
- If a marker comment exists, update it with latest findings.
- Otherwise create a new PR comment.
- If there are no findings and marker comment exists, edit marker comment to a short pass status.
Suggested comment format:
<!-- pr-auto-review -->
## Auto Review
- [Rule] file: issue + suggestion
For no findings:
<!-- pr-auto-review -->
## Auto Review
No clear rule violations found in the current diff.
Use only gh commands and repository data."