name: OpenCode PR Review on: # Using pull_request (not pull_request_target) because the OpenCode action # doesn't support pull_request_target. This means it only works for PRs from # branches in this repo (not forks). Fork PRs are reviewed by claude-code-review.yml instead. pull_request: types: [opened, synchronize] # Skip review for documentation and config-only changes # Exclude this workflow file to prevent self-triggering loops paths-ignore: - "**/*.md" - ".github/workflows/opencode-review.yml" - ".gitignore" - "pyproject.toml" # Cancel in-progress runs for the same PR to avoid duplicate reviews concurrency: group: opencode-review-${{ github.event.pull_request.number }} cancel-in-progress: true jobs: opencode-review: runs-on: ubuntu-latest timeout-minutes: 10 # Prevent hanging - kill after 10 min permissions: id-token: write contents: read pull-requests: write issues: write steps: - name: Calculate total changes id: calc run: | additions=${{ github.event.pull_request.additions }} deletions=${{ github.event.pull_request.deletions }} total=$((additions + deletions)) echo "total=$total" >> $GITHUB_OUTPUT - name: Checkout repository # Only review substantial changes (5+ files OR 20+ lines changed) if: | github.event.pull_request.changed_files >= 5 || steps.calc.outputs.total >= 20 uses: actions/checkout@v6 with: fetch-depth: 1 persist-credentials: false - name: Clear git credentials to avoid duplicate auth if: | github.event.pull_request.changed_files >= 5 || steps.calc.outputs.total >= 20 run: | # Clear all GitHub-related git config to prevent auth conflicts git config --global --unset-all http.https://github.com/.extraheader || true git config --local --unset-all http.https://github.com/.extraheader || true git config --global --unset-all credential.helper || true git config --local --unset-all credential.helper || true git config --global --unset-all credential."https://github.com".helper || true git config --local --unset-all credential."https://github.com".helper || true # Remove any credential URLs git config --global --unset-all credential.url || true git config --local --unset-all credential.url || true # Clear any includeIf configs that might add credentials # Note: git config doesn't support wildcards, so we iterate over matching keys # Use case-insensitive grep to catch both "includeIf" and "includeif" for key in $(git config --global --list --name-only 2>/dev/null | grep -i "^includeif\." || true); do git config --global --unset "$key" || true done for key in $(git config --local --list --name-only 2>/dev/null | grep -i "^includeif\." || true); do git config --local --unset "$key" || true done - name: Run OpenCode PR Review # Only review substantial changes (5+ files OR 20+ lines changed) if: | github.event.pull_request.changed_files >= 5 || steps.calc.outputs.total >= 20 uses: anomalyco/opencode/github@latest env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} ZHIPU_API_KEY: ${{ secrets.ZHIPU_API_KEY }} # Pass PR context as environment variables for the review PR_NUMBER: ${{ github.event.pull_request.number }} PR_TITLE: ${{ github.event.pull_request.title }} PR_BODY: ${{ github.event.pull_request.body }} REPO_NAME: ${{ github.repository }} with: model: zai-coding-plan/glm-4.7 use_github_token: true prompt: | You are reviewing PR #${{ github.event.pull_request.number }} in repository ${{ github.repository }}. PR TITLE: ${{ github.event.pull_request.title }} Please review this pull request and provide feedback on: - Code quality and best practices - Potential bugs or issues - Performance considerations - Security concerns - Test coverage IMPORTANT NOTES: - Review the other comments on the pull request - including any prior reviews. - If you are reviewing changes beyond the first creation of the pull request, make sure your comments are consistent with previous reviews. - There's no need to repeat information unless it is critical and not being reflected in comments or code. - Be aware of prior reviews and that new file information may reflect changes because of previous reviews. Use the repository's CLAUDE.md for guidance on style and conventions. Be constructive and helpful in your feedback. IMPORTANT: Post exactly ONE comment using `gh pr comment`, then STOP. Do not attempt additional actions after posting your review.