Updated Gemini Automatic Code Review Agent - #268
Conversation
|
🤖 Gemini Code Review |
|
🤖 Gemini Code Review |
|
🤖 Gemini Code Review Hey team! Automating initial code reviews using Gemini is a fantastic idea. This will give students instant feedback on their PRs before mentors do a manual pass, which will really speed up our development cycles. Here is my review of the workflow file. Overall, the logic is solid, but there are a couple of key bugs and improvements to address before we merge this. 🚨 Critical Issues & Bugs1. Invalid Gemini Model NameIn the inline Python script, the endpoint URL specifies model url = 'https://generativelanguage.googleapis.com/v1beta/models/gemini-3.6-flash:generateContent'
url = 'https://generativelanguage.googleapis.com/v1beta/models/gemini-1.5-flash:generateContent'2. Workflow Failures on Forked PRs / Missing SecretWhen a PR is opened from a repository fork (e.g., a student working on their own fork), GitHub Actions intentionally strips access to repository secrets like Currently, if if not api_key:
print('Error: GEMINI_API_KEY secret is not set.')
sys.exit(1)
if not api_key:
print('Warning: GEMINI_API_KEY secret is not set. Skipping review.')
with open('review.md', 'w', encoding='utf-8') as f:
f.write('🤖 **Gemini Code Review**: Skipping review (GEMINI_API_KEY secret not accessible on this run).\n')
sys.exit(0)💡 Suggested Enhancements1. Diff Size Limit vs. Gemini Context WindowIn Step 2, the diff is truncated to 20,000 characters (~5,000 tokens): head -c 20000 pr_diff.txt > trimmed_diff.txt
2. Filtering Non-Code Files (FRC-Specific)WPILib projects frequently include large JSON vendor dependency files (
# Example: Exclude vendordeps and gradle wrapper updates from diff
gh pr diff "$PR_NUM" --repo "${{ github.repository }}" | grep -v "vendordeps/" > pr_diff.txtSummary Checklist
Great work setting up CI automation for the team! Make these quick tweaks and tag me for re-review! 🚀 |
|
🤖 Gemini Code Review |
|
🤖 Gemini Code Review Hey team! Great initiative setting up automated PR reviews for our robot codebase. Using Gemini to automatically check PRs for WPILib best practices and safety bugs is going to save us a lot of time during build season! I reviewed the workflow configuration file. We have a few critical bugs that will prevent the workflow from running successfully, along with a couple of improvements for robustness and API best practices. 🚨 Critical Issues (Will Cause Workflow Failure)1. Missing PR Diff Generation (
|
|
🤖 Gemini Code Review Hey team! Great initiative setting up an automated code review workflow using Gemini and GitHub Actions! This will be a super helpful tool for providing quick feedback to students on their pull requests before mentors do a manual review. While reviewing the workflow file, I found a couple of critical issues that will cause the action to fail when triggered, along with a few recommendations to make it more robust. 🚨 Critical Issues (Will Cause Workflow Failure)1.
|
|
🤖 Gemini Code Review Hey team! This is a great initiative to automate code reviews and help teach team members WPILib best practices right in Pull Requests. I reviewed the GitHub Actions workflow configuration and found a few critical issues that will cause the workflow to fail at runtime, as well as an unused file fetch. 🚨 Critical Issues & Bugs1.
|
|
🤖 Gemini Code Review Hey team! Great work setting up an automated PR review workflow with Gemini. Adding automated checks like this is a huge help for keeping our WPILib standards high and giving students quick feedback before mentors jump in for final reviews. Here is a review of the workflow setup and a few small improvements we can make for safety, maintainability, and reliability. Key Observations & Recommendations1. Bash String Handling for User Comments (Robustness)In if [ "$EVENT_NAME" = "issue_comment" ]; then
EXTRA=$(echo "$USER_COMMENT" | sed 's/\/gemini//g' | xargs)
if [ -n "$EXTRA" ]; then
export SYSTEM_INSTRUCTION="$SYSTEM_INSTRUCTION Student note: $EXTRA"
fi
fi
Suggested Fix: Move the comment parsing into the Python block: user_comment = os.environ.get('USER_COMMENT', '')
if os.environ.get('EVENT_NAME') == 'issue_comment' and '/gemini' in user_comment:
extra_note = user_comment.replace('/gemini', '').strip()
if extra_note:
system_instruction += f"\nStudent note: {extra_note}"2. API Error Response Details (Debugging)In the Python review script: try:
with urllib.request.urlopen(req) as res:
...
except Exception as e:
review_content = f'⚠️ Failed to generate review from Gemini: {e}'
Example Catch Block: import urllib.error
try:
with urllib.request.urlopen(req) as res:
res_data = json.loads(res.read().decode('utf-8'))
# ... process response
except urllib.error.HTTPError as e:
err_body = e.read().decode('utf-8')
review_content = f'⚠️ Gemini API Error ({e.code}): {err_body}'
except Exception as e:
review_content = f'⚠️ Failed to generate review from Gemini: {e}'3. Rules Fetching from BranchesIn Step 2: gh api "repos/${{ github.repository }}/contents/.github/reviewer-rules.md" \
-H "Accept: application/vnd.github.raw+json" > rules.txt 2>/dev.null || touch rules.txt
SummaryOverall, this is a clean, dependency-free Python + GitHub CLI implementation that avoids external library overhead. Once we tweak the string handling and HTTP error logging, this workflow will be rock solid for the team. Nice job! |
|
🤖 Gemini Code Review Hey team! Great job setting up this automated code review action for our repository. Integrating LLM-assisted code reviews into our PR workflow is a fantastic way to give students quick feedback on WPILib conventions and safety before mentor reviews. Here is a review of the workflow and configuration files from a best practices, safety, and reliability standpoint. Highlights & Good Practices 👏
Potential Issues & Recommended Improvements 🔧1. Fragile Shell Manipulation of User Comments (
|
| Area | Status | Notes |
|---|---|---|
| Model Version | ✅ Pass | Pinning gemini-3.6-flash as specified in rules. |
| Permissions | ✅ Pass | Minimal write permissions for PR/issue commenting. |
| String Parsing | Replace shell sed/xargs with native Python parsing. |
Once the shell string handling is refactored into Python, this PR is ready to merge! Great work setting this infrastructure up for the team.
|
🤖 Gemini Code Review Summary This PR adds a automated code review workflow using Gemini via GitHub Actions, alongside reviewer instructions in |
|
🤖 Gemini Code Review Summary Reviewed the workflow configuration and the Python script used for the code review. The pipeline securely handles payload values using environment variables rather than direct bash interpolations. Recommended improvements focus on protecting against null references in GitHub Actions expressions and adding robust error handling for highly nested API responses. |
|
🤖 Gemini Code Review Summary Added project reviewer rules documentation and configured a GitHub Actions workflow for automated AI PR reviews using Gemini. |
|
|
||
| # Download PR diff | ||
| gh pr diff "$PR_NUM" --repo "${{ github.repository }}" > pr_diff.txt | ||
| head -c 25000 pr_diff.txt > trimmed_diff.txt |
There was a problem hiding this comment.
🤖 Using head -c 25000 truncates the diff by exact byte count, which can cut off a line or diff hunk in the middle. Using line-based truncation (e.g., head -n 500) preserves complete diff lines and prevents sending malformed diff fragments to the reviewer model.
| raw_text = res_data['candidates'][0]['content']['parts'][0]['text'].strip() | ||
| # Clean potential markdown wraps from response | ||
| if raw_text.startswith("```json"): | ||
| raw_text = raw_text[7:] |
There was a problem hiding this comment.
🤖 Trailing whitespace or newlines after the closing backticks can cause raw_text.endswith("```") to evaluate to False. Calling raw_text = raw_text.strip() right before checking endswith("```") ensures markdown code block formatting is reliably stripped before JSON parsing.
Google is ending support for their consumer version of Google Code Assist. According to my research this change MAY still work and enable automatic as well as trigger (by /gemini command) code reviews in our repository.
Unfortunately, this needs to be checked into main to see if it works...