Enhance presubmit.yml for AI review conditions #453
Workflow file for this run
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Presubmit.ai | |
| permissions: | |
| contents: read | |
| pull-requests: write | |
| issues: write | |
| on: | |
| pull_request_target: # Handle forked repository PRs in the base repository context | |
| types: [opened, synchronize] | |
| pull_request_review_comment: # Handle review comments | |
| types: [created] | |
| jobs: | |
| review: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Check out PR code | |
| uses: actions/checkout@v3 | |
| with: | |
| ref: ${{ github.event.pull_request.head.sha }} | |
| - name: Run AI Reviewer | |
| uses: presubmit/ai-reviewer@latest | |
| if: ${{ !github.event.pull_request.head.repo.fork && (secrets.LLM_API_KEY != '' || secrets.OPENAI_API_KEY != '') }} | |
| continue-on-error: true | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| # Prefer OpenAI if available, else fall back to generic LLM_API_KEY (e.g., Gemini) | |
| LLM_API_KEY: ${{ secrets.OPENAI_API_KEY != '' && secrets.OPENAI_API_KEY || secrets.LLM_API_KEY }} | |
| # Allow override via secret LLM_MODEL; fallback to a default | |
| # Note: Some models may not be supported by the action's underlying API client. | |
| # Set repository secret LLM_MODEL to a model known to work in your account. | |
| # Default to a broadly available model per provider: | |
| # - If OPENAI_API_KEY is present: gpt-4o-mini | |
| # - Else: gemini-1.0-pro | |
| LLM_MODEL: ${{ secrets.LLM_MODEL != '' && secrets.LLM_MODEL || (secrets.OPENAI_API_KEY != '' && 'gpt-4o-mini' || 'gemini-1.0-pro') }} | |
| - name: Skip reason (forks or missing secret) | |
| if: ${{ github.event.pull_request.head.repo.fork || (secrets.LLM_API_KEY == '' && secrets.OPENAI_API_KEY == '') }} | |
| run: | | |
| echo "AI review skipped." | |
| if [ "${{ github.event.pull_request.head.repo.fork }}" = "true" ]; then | |
| echo "Reason: PR comes from a fork; skipping AI review to avoid secret/model issues." | |
| fi | |
| if [ -z "${{ secrets.LLM_API_KEY }}" ] && [ -z "${{ secrets.OPENAI_API_KEY }}" ]; then | |
| echo "Reason: Neither LLM_API_KEY (Gemini) nor OPENAI_API_KEY (OpenAI) is configured." | |
| echo "Set one of these secrets and optionally LLM_MODEL to enable AI review." | |
| fi |