# Copy to .github/workflows/codejackrabbit-review.yml in any repository.
# This workflow downloads the private CodeJackRabbit CLI release from
# Cloudflare R2; it does not require access to the product source.
name: CodeJackRabbit Review
on:
  pull_request:
    types: [opened, synchronize, reopened, ready_for_review]
permissions:
  contents: read
jobs:
  review:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
        with:
          fetch-depth: 0
      - name: Install CodeJackRabbit CLI
        shell: bash
        run: |
          set -euo pipefail
          manifest="$(curl -fsSL https://cli.codejackrabbit.com/releases/latest.json)"
          url="$(MANIFEST="$manifest" python3 -c 'import json, os; data=json.loads(os.environ["MANIFEST"]); print(next(a["url"] for a in data["assets"] if a["platform"] == "linux-x64"))')"
          curl -fsSL "$url" -o /usr/local/bin/cjr
          chmod +x /usr/local/bin/cjr
          cjr --version
      - name: Review pull request changes
        shell: bash
        run: cjr review --local --committed --base "origin/${{ github.base_ref }}" --fail-on none
        # Server mode example:
        # env:
        #   CODEJACKRABBIT_API_KEY: ${{ secrets.CODEJACKRABBIT_API_KEY }}
        # run: |
        #   cjr auth login --api-key "$CODEJACKRABBIT_API_KEY" --host-url https://api.codejackrabbit.com --agent
        #   cjr review --committed --base "origin/${{ github.base_ref }}" --fail-on none
