148 lines
6.5 KiB
YAML
148 lines
6.5 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@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@ecf28ddc73e819eb6fa29df6b34ef8921c743461 # v2.1.3
|
|
|
|
- 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.
|
|
|
|
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."
|