Skip to content

pr-review

pr-review #1604

Workflow file for this run

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@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
# 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 }}
PR_BRANCH: |-
${{
(github.event.workflow_run.head_repository.owner.login != github.event.workflow_run.repository.owner.login)
&& format('{0}:{1}', github.event.workflow_run.head_repository.owner.login, github.event.workflow_run.head_branch)
|| github.event.workflow_run.head_branch
}}
run: |
gh pr view --repo "${PR_TARGET_REPO}" "${PR_BRANCH}" \
--json 'number' --jq '"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: Set up Bun
if: github.event_name == 'workflow_dispatch' || (steps.check-pr-author.outputs.skip != 'true' && github.event.workflow_run.conclusion != 'failure')
uses: oven-sh/setup-bun@0c5077e51419868618aeaa5fe8019c62421857d6 # v2.2.0
- name: Install opencode
if: github.event_name == 'workflow_dispatch' || (steps.check-pr-author.outputs.skip != 'true' && github.event.workflow_run.conclusion != 'failure')
run: curl -fsSL https://opencode.ai/install | bash
- name: Review PR with rules
if: github.event_name == 'workflow_dispatch' || (steps.check-pr-author.outputs.skip != 'true' && github.event.workflow_run.conclusion != 'failure')
env:
OPENCODE_API_KEY: ${{ secrets.OPENCODE_API_KEY }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GITHUB_REPOSITORY: ${{ github.repository }}
PR_NUMBER: ${{ steps.source-run-info.outputs.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.
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."