Skip to content

Commit 658ad44

Browse files
authored
Enhance presubmit.yml for AI review conditions
Updated AI review workflow to handle secrets and forked PRs.
1 parent ede37bd commit 658ad44

File tree

1 file changed

+22
-9
lines changed

1 file changed

+22
-9
lines changed

.github/workflows/presubmit.yml

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,21 +15,34 @@ jobs:
1515
review:
1616
runs-on: ubuntu-latest
1717
steps:
18-
- name: Check required secrets
19-
run: |
20-
if [ -z "${{ secrets.LLM_API_KEY }}" ]; then
21-
echo "Error: LLM_API_KEY secret is not configured"
22-
exit 1
23-
fi
24-
2518
- name: Check out PR code
2619
uses: actions/checkout@v3
2720
with:
2821
ref: ${{ github.event.pull_request.head.sha }}
2922

3023
- name: Run AI Reviewer
3124
uses: presubmit/ai-reviewer@latest
25+
if: ${{ !github.event.pull_request.head.repo.fork && (secrets.LLM_API_KEY != '' || secrets.OPENAI_API_KEY != '') }}
26+
continue-on-error: true
3227
env:
3328
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
34-
LLM_API_KEY: ${{ secrets.LLM_API_KEY }}
35-
LLM_MODEL: "gemini-1.5-flash"
29+
# Prefer OpenAI if available, else fall back to generic LLM_API_KEY (e.g., Gemini)
30+
LLM_API_KEY: ${{ secrets.OPENAI_API_KEY != '' && secrets.OPENAI_API_KEY || secrets.LLM_API_KEY }}
31+
# Allow override via secret LLM_MODEL; fallback to a default
32+
# Note: Some models may not be supported by the action's underlying API client.
33+
# Set repository secret LLM_MODEL to a model known to work in your account.
34+
# Default to a broadly available model per provider:
35+
# - If OPENAI_API_KEY is present: gpt-4o-mini
36+
# - Else: gemini-1.0-pro
37+
LLM_MODEL: ${{ secrets.LLM_MODEL != '' && secrets.LLM_MODEL || (secrets.OPENAI_API_KEY != '' && 'gpt-4o-mini' || 'gemini-1.0-pro') }}
38+
- name: Skip reason (forks or missing secret)
39+
if: ${{ github.event.pull_request.head.repo.fork || (secrets.LLM_API_KEY == '' && secrets.OPENAI_API_KEY == '') }}
40+
run: |
41+
echo "AI review skipped."
42+
if [ "${{ github.event.pull_request.head.repo.fork }}" = "true" ]; then
43+
echo "Reason: PR comes from a fork; skipping AI review to avoid secret/model issues."
44+
fi
45+
if [ -z "${{ secrets.LLM_API_KEY }}" ] && [ -z "${{ secrets.OPENAI_API_KEY }}" ]; then
46+
echo "Reason: Neither LLM_API_KEY (Gemini) nor OPENAI_API_KEY (OpenAI) is configured."
47+
echo "Set one of these secrets and optionally LLM_MODEL to enable AI review."
48+
fi

0 commit comments

Comments
 (0)