name: "Gito: AI Code Reviewer"
on:
  pull_request:
    types: [opened, synchronize, reopened]
  workflow_dispatch:
    inputs:
      pr_number:
        description: "Pull Request number"
        required: true
jobs:
  review:
    runs-on: ubuntu-latest
    permissions: { contents: read, pull-requests: write } # 'write' for leaving the summary comment
    steps:
    - uses: actions/checkout@v4
      with: { fetch-depth: 0 }

    {%- include("github_workflows/components/installs.j2") %}

    - name: Run AI code review
      env:
        {%- include("github_workflows/components/env-vars.j2") %}
        PR_NUMBER_FROM_WORKFLOW_DISPATCH: {% raw %}${{ github.event.inputs.pr_number }}{% endraw %}
      run: |{% raw %}
        gito --verbose review
        gito github-comment{% endraw %}

    - uses: actions/upload-artifact@v4
      with:
        name: gito-code-review-results
        path: |
          code-review-report.md
          code-review-report.json