RSSHub/.github/workflows/pr-review.yml

153 lines
8.0 KiB
YAML

name: pr-review
on:
workflow_run:
workflows: [PR - Docker build test]
types: [completed]
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.workflow_run.conclusion == 'success'
runs-on: ubuntu-latest
timeout-minutes: 10
permissions:
contents: read
issues: write
pull-requests: write
steps:
- name: Checkout repository
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
# https://github.com/orgs/community/discussions/25220#discussioncomment-11316244
- name: Search the PR that triggered this workflow
if: github.event_name != 'workflow_dispatch'
id: source-run-info
env:
GH_TOKEN: ${{ github.token }}
PR_TARGET_REPO: ${{ github.repository }}
# The REST API `head` filter requires `<owner>:<branch>` format
PR_BRANCH: ${{ format('{0}:{1}', github.event.workflow_run.head_repository.owner.login, github.event.workflow_run.head_branch) }}
run: |
gh api "repos/${PR_TARGET_REPO}/pulls" \
--method GET -f head="${PR_BRANCH}" -f state=open \
--jq '.[0] | "number=\(.number)"' \
>> "${GITHUB_OUTPUT}"
- name: Check PR author
if: github.event_name != 'workflow_dispatch'
id: check-pr-author
env:
GH_TOKEN: ${{ github.token }}
PR_TARGET_REPO: ${{ github.repository }}
PR_NUMBER: ${{ steps.source-run-info.outputs.number }}
run: |
AUTHOR=$(gh pr view --repo "${PR_TARGET_REPO}" "${PR_NUMBER}" --json author --jq '.author.login')
echo "author=${AUTHOR}" >> "${GITHUB_OUTPUT}"
if [[ "${AUTHOR}" == "dependabot[bot]" || "${AUTHOR}" == "app/dependabot" ]]; then
echo "skip=true" >> "${GITHUB_OUTPUT}"
else
echo "skip=false" >> "${GITHUB_OUTPUT}"
fi
- name: Comment on failed Docker build
if: github.event_name != 'workflow_dispatch' && github.event.workflow_run.conclusion == 'failure'
env:
GH_TOKEN: ${{ github.token }}
PR_TARGET_REPO: ${{ github.repository }}
PR_NUMBER: ${{ steps.source-run-info.outputs.number }}
run: |
gh pr comment --repo "${PR_TARGET_REPO}" "${PR_NUMBER}" --body "<!-- pr-auto-review -->
## Auto Review
⚠️ PR review will proceed after the Docker image can be successfully built.
Please fix the Docker build test issues first."
- name: Check PR number
if: github.event_name == 'workflow_dispatch' || (steps.check-pr-author.outputs.skip != 'true' && github.event.workflow_run.conclusion != 'failure')
env:
PR_NUMBER: ${{ steps.source-run-info.outputs.number || inputs.pr_number }}
run: |
if [ -z "$PR_NUMBER" ]; then
echo "pr_number is required"
exit 1
fi
- name: Review PR with rules
if: github.event_name == 'workflow_dispatch' || (steps.check-pr-author.outputs.skip != 'true' && github.event.workflow_run.conclusion != 'failure')
uses: anthropics/claude-code-action@v1
env:
GH_TOKEN: ${{ github.token }}
PR_NUMBER: ${{ steps.source-run-info.outputs.number || inputs.pr_number }}
with:
claude_code_oauth_token: ${{ secrets.CLAUDE_CODE_OAUTH_TOKEN }}
github_token: ${{ secrets.GITHUB_TOKEN }}
display_report: 'true'
claude_args: |
--model ${{ vars.OPENCODE_MODEL }}
${{ vars.CLAUDE_EFFORT && format('--effort {0}', vars.CLAUDE_EFFORT) || '' }}
--allowedTools "Bash(base64:*),Bash(cat:*),Bash(echo:*),Bash(gh api:*),Bash(gh auth:*),Bash(gh pr comment:*),Bash(gh pr diff:*),Bash(gh pr view:*),Bash(gh repo view:*),Bash(gh search:*),Bash(git diff:*),Bash(git log:*),Bash(git show:*),Bash(git status:*),Bash(grep:*),Bash(head:*),Bash(ls:*),Bash(rg:*),Bash(sed:*),Bash(tail:*),Bash(wc:*),${{ github.event_name == 'workflow_dispatch' && 'WebFetch,WebSearch' || 'WebFetch(domain:docs.rsshub.app)' }}"
${{ github.event_name != 'workflow_dispatch' && '--disallowedTools "WebSearch"' || '' }}
prompt: |
A pull request has been created or updated in this repository.
Pull request number:
${{ steps.source-run-info.outputs.number || inputs.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:
Read them from .github/prompts/pr_review_rules.md and AGENTS.md in the checked-out repository.
Also read the script standard at https://docs.rsshub.app/joinus/advanced/script-standard and apply it to changed route scripts.
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.
gh command reference (PR_NUMBER and GITHUB_REPOSITORY are available as env vars):
- Create a new PR comment:
gh pr comment "$PR_NUMBER" --repo "$GITHUB_REPOSITORY" --body "<!-- pr-auto-review -->
## Auto Review
..."
- List existing marker comments to find the one to update:
gh pr view "$PR_NUMBER" --repo "$GITHUB_REPOSITORY" --json comments \
--jq '.comments[] | select(.body | startswith("<!-- pr-auto-review -->")) | {id: .id, body: .body}'
- Update an existing marker comment (use the numeric id from the URL, not the node id):
gh api "repos/$GITHUB_REPOSITORY/issues/comments/<comment_id>" -X PATCH -f body="<!-- pr-auto-review -->
## Auto Review
..."
- Prefer --body-file - with a heredoc when the body contains quotes or many lines.
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.