name: OpenCode PR review

on:
  pull_request:
    types: [opened, synchronize, reopened, ready_for_review]

jobs:
  review:
    if: github.event.pull_request.head.repo.full_name == github.repository || github.event.pull_request.author_association == 'MEMBER' || github.event.pull_request.author_association == 'OWNER' || github.event.pull_request.author_association == 'COLLABORATOR'
    runs-on: ubuntu-latest
    permissions:
      id-token: write
      contents: read
      pull-requests: write
      issues: write
    steps:
      # Runs only for same-repo or trusted contributors. Fork PRs from outsiders may not
      # have enough token permissions for automatic review comments.
      - name: Checkout repository
        uses: actions/checkout@v4
        with:
          persist-credentials: false
          fetch-depth: 0

      - name: Configure git identity
        run: |
          git config --global user.name "github-actions[bot]"
          git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com"

      - uses: anomalyco/opencode/github@latest
        env:
          GITHUB_TOKEN: ${{ github.token }}
        with:
          model: opencode/deepseek-v4-flash-free
          use_github_token: true
          prompt: |
            Review this pull request:
            - Check for code quality issues
            - Look for potential bugs
            - Suggest improvements
            Your response should contain:
            - A score "Confidence Score" from 1 to 5
            - Any issues you detected in the PR, properly formatted into codeblocks.
