Upgrade proposal card #161
Workflow file for this run
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: "Code Review by Gemini AI" | |
on: | |
pull_request: | |
jobs: | |
review: | |
runs-on: ubuntu-latest | |
permissions: | |
contents: read | |
pull-requests: write | |
steps: | |
- uses: actions/checkout@v3 | |
- name: "Check for !ai keyword in commit message" | |
id: check_commit_message | |
run: | | |
COMMIT_MESSAGE=$(git log -1 --pretty=%B) | |
echo "Commit message: $COMMIT_MESSAGE" | |
if [[ "$COMMIT_MESSAGE" == *"!ai"* ]]; then | |
echo "run_ai=true" >> $GITHUB_ENV | |
else | |
echo "run_ai=false" >> $GITHUB_ENV | |
fi | |
- name: "Check if relevant files are modified" | |
id: check_changes | |
shell: bash | |
run: | | |
# Check for modified .ts, .tsx, or .sol files | |
git fetch origin "${{ github.event.pull_request.head.ref }}" # fetch the branch with changes | |
git fetch origin "${{ github.event.pull_request.base.ref }}" # fetch the target branch | |
git diff --name-only "origin/${{ github.event.pull_request.base.ref }}" "origin/${{ github.event.pull_request.head.ref }}" > modified_files.txt | |
# Check if there are any .ts, .tsx, or .sol files modified | |
if grep -E '\.ts$|\.tsx$|\.sol$' modified_files.txt; then | |
echo "files_changed=true" >> $GITHUB_ENV | |
else | |
echo "files_changed=false" >> $GITHUB_ENV | |
fi | |
- name: "Get diff of the pull request" | |
if: env.files_changed == 'true' && env.run_ai == 'true' | |
id: get_diff | |
shell: bash | |
env: | |
PULL_REQUEST_HEAD_REF: "${{ github.event.pull_request.head.ref }}" | |
PULL_REQUEST_BASE_REF: "${{ github.event.pull_request.base.ref }}" | |
run: |- | |
# Only include changes to .ts, .tsx, and .sol files in the diff | |
git diff "origin/${{ env.PULL_REQUEST_BASE_REF }}" -- '*.ts' '*.tsx' '*.sol' > "diff.txt" | |
{ | |
echo "pull_request_diff<<EOF"; | |
cat "diff.txt"; | |
echo 'EOF'; | |
} >> $GITHUB_OUTPUT # save the filtered diff to an output variable | |
- uses: rubensflinco/[email protected] | |
name: "Code Review by Gemini AI" | |
if: env.files_changed == 'true' && env.run_ai == 'true' | |
continue-on-error: true | |
id: review | |
with: | |
gemini_api_key: ${{ secrets.GEMINI_API_KEY }} | |
github_token: ${{ secrets.GITHUB_TOKEN }} | |
github_repository: ${{ github.repository }} | |
github_pull_request_number: ${{ github.event.pull_request.number }} | |
git_commit_hash: ${{ github.event.pull_request.head.sha }} | |
model: "gemini-1.5-pro-latest" | |
pull_request_diff: |- | |
${{ steps.get_diff.outputs.pull_request_diff }} | |
pull_request_chunk_size: "3500" | |
extra_prompt: |- | |
Only review files with extensions: .ts, .tsx, .sol | |
Focus your review on code logic, security vulnerabilities, and potential improvements in these files. | |
log_level: "DEBUG" |