test #21
This file contains 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: Gemini PR Review | |
on: | |
pull_request: | |
types: [opened, synchronize] # Triggers on PR open and code updates | |
jobs: | |
gemini_review: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v3 | |
with: | |
fetch-depth: 0 # seems necessary to diff with master instead of using HEAD | |
- name: Set up Python | |
uses: actions/setup-python@v4 | |
with: | |
python-version: '3.9' | |
- name: Install dependencies | |
run: | | |
python -m pip install --upgrade pip | |
pip install google-generativeai | |
- name: Get PR diff | |
id: get_diff | |
run: | | |
echo "DIFF<<EOF" >> $GITHUB_OUTPUT | |
echo $(git diff origin/${GITHUB_BASE_REF}...origin/${GITHUB_HEAD_REF} | base64) >> $GITHUB_OUTPUT | |
echo "EOF" >> $GITHUB_OUTPUT | |
- name: Gemini API Call | |
id: gemini_review_call | |
run: | | |
python <<EOF | |
import os, base64 | |
import google.generativeai as genai | |
genai.configure(api_key=os.environ['GEMINI_API_KEY']) | |
model = genai.GenerativeModel('gemini-pro') | |
diff_encoded = "${{ steps.get_diff.outputs.DIFF }}".strip() | |
diff = base64.b64decode(diff_encoded).decode('utf-8') | |
prompt = f"Review this code diff for potential issues and provide feedback:\n\n {diff}" | |
response = model.generate_content(prompt) | |
print(f"REVIEW<<EOF") | |
print(response.text) | |
print(f"EOF") | |
EOF | |
env: | |
GEMINI_API_KEY: ${{ secrets.GEMINI_API_KEY }} | |
- name: Post Review Comment (Placeholder) | |
run: | | |
echo "This is a placeholder for posting a review comment." | |
echo "Gemini Review: ${{ steps.gemini_review_call.outputs.REVIEW }}" |