Prepare ai code review
All checks were successful
Ruby on Rails Test / rails-test (push) Successful in 1m49s
All checks were successful
Ruby on Rails Test / rails-test (push) Successful in 1m49s
This commit is contained in:
93
.gitea/workflows/ai-code-review.yaml.old
Normal file
93
.gitea/workflows/ai-code-review.yaml.old
Normal file
@@ -0,0 +1,93 @@
|
||||
name: AI Code Review
|
||||
run-name: AI Code Review by @${{ github.actor }} 🤖
|
||||
|
||||
on:
|
||||
pull_request:
|
||||
types: [opened, synchronize]
|
||||
|
||||
jobs:
|
||||
ai-review:
|
||||
runs-on: ubuntu-22.04
|
||||
steps:
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
fetch-depth: 0
|
||||
|
||||
- name: Get PR diff
|
||||
id: diff
|
||||
run: |
|
||||
# Get the diff for the PR
|
||||
git fetch origin ${{ github.base_ref }}
|
||||
DIFF=$(git diff origin/${{ github.base_ref }}...HEAD)
|
||||
echo "diff<<EOF" >> $GITHUB_OUTPUT
|
||||
echo "$DIFF" >> $GITHUB_OUTPUT
|
||||
echo "EOF" >> $GITHUB_OUTPUT
|
||||
|
||||
- name: AI Code Review
|
||||
env:
|
||||
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
|
||||
# Or use ANTHROPIC_API_KEY for Claude
|
||||
# ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }}
|
||||
run: |
|
||||
# Install dependencies
|
||||
pip install openai requests
|
||||
|
||||
# Create review script
|
||||
cat > review.py << 'EOF'
|
||||
import os
|
||||
import openai
|
||||
import requests
|
||||
import json
|
||||
|
||||
# Configure OpenAI client (or use Anthropic client for Claude)
|
||||
client = openai.OpenAI(api_key=os.environ['OPENAI_API_KEY'])
|
||||
|
||||
# Get diff from environment
|
||||
diff = """${{ steps.diff.outputs.diff }}"""
|
||||
|
||||
if not diff.strip():
|
||||
print("No changes to review")
|
||||
exit(0)
|
||||
|
||||
# Create review prompt
|
||||
prompt = f"""
|
||||
Please review this code diff and provide constructive feedback:
|
||||
|
||||
{diff}
|
||||
|
||||
Focus on:
|
||||
- Code quality and best practices
|
||||
- Potential bugs or security issues
|
||||
- Performance considerations
|
||||
- Maintainability and readability
|
||||
- Ruby on Rails specific patterns
|
||||
|
||||
Provide your review as structured feedback with specific line references where possible.
|
||||
"""
|
||||
|
||||
try:
|
||||
response = client.chat.completions.create(
|
||||
model="gpt-4", # or "claude-3-sonnet" for Claude
|
||||
messages=[{"role": "user", "content": prompt}],
|
||||
max_tokens=2000
|
||||
)
|
||||
|
||||
review = response.choices[0].message.content
|
||||
print("AI Code Review:")
|
||||
print("=" * 50)
|
||||
print(review)
|
||||
|
||||
# Post review as PR comment (requires additional API setup)
|
||||
# This would need Gitea API integration
|
||||
|
||||
except Exception as e:
|
||||
print(f"Error during review: {e}")
|
||||
EOF
|
||||
|
||||
python review.py
|
||||
|
||||
- name: Comment on PR
|
||||
if: always()
|
||||
run: |
|
||||
echo "Review completed - implement Gitea API integration to post comments"
|
||||
Reference in New Issue
Block a user