Skip to content

Feat/neonevm solana

Feat/neonevm solana #1

name: Claude AI PR Review
on:
pull_request:
types: [opened, synchronize, reopened]
pull_request_review_comment:
types: [created]
jobs:
claude-review:
runs-on: ubuntu-latest
permissions:
contents: read
pull-requests: write
issues: write
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Get PR changes
id: changes
run: |
# Get the list of changed files
git diff --name-only origin/${{ github.base_ref }}..HEAD > changed_files.txt
# Get the diff content
git diff origin/${{ github.base_ref }}..HEAD > changes.diff
echo "Changed files:"
cat changed_files.txt
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v4
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: ${{ secrets.AWS_REGION }}
- name: Setup Python
uses: actions/setup-python@v4
with:
python-version: '3.11'
- name: Install dependencies
run: |
pip install boto3 requests
- name: Run Claude PR Review
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
AWS_BEDROCK_MODEL_ID: ${{ secrets.AWS_BEDROCK_MODEL_ID }}
run: |
cat << 'EOF' > claude_review.py
import boto3
import json
import os
import requests
import base64
def get_bedrock_client():
return boto3.client('bedrock-runtime', region_name=os.environ['AWS_DEFAULT_REGION'])
def analyze_with_claude(diff_content, changed_files):
client = get_bedrock_client()
prompt = f"""
You are an expert code reviewer. Please review the following code changes and provide constructive feedback.
Changed files: {', '.join(changed_files)}
Code diff:
```diff
{diff_content}
```
Please provide:
1. Overall assessment of the changes
2. Potential issues or bugs
3. Code quality suggestions
4. Security considerations
5. Performance implications
6. Suggestions for improvement
Focus on being constructive and helpful. If the code looks good, mention what's done well.
"""
body = {
"anthropic_version": "bedrock-2023-05-31",
"max_tokens": 4000,
"messages": [
{
"role": "user",
"content": prompt
}
]
}
response = client.invoke_model(
body=json.dumps(body),
modelId=os.environ.get('AWS_BEDROCK_MODEL_ID', 'anthropic.claude-3-sonnet-20240229-v1:0'),
accept='application/json',
contentType='application/json'
)
response_body = json.loads(response.get('body').read())
return response_body['content'][0]['text']
def post_pr_comment(review_content):
github_token = os.environ['GITHUB_TOKEN']
repo = os.environ['GITHUB_REPOSITORY']
pr_number = os.environ['GITHUB_PR_NUMBER'] if 'GITHUB_PR_NUMBER' in os.environ else os.environ['GITHUB_REF'].split('/')[-2]
headers = {
'Authorization': f'token {github_token}',
'Accept': 'application/vnd.github.v3+json'
}
comment_body = f"""## 🤖 Claude AI Code Review
{review_content}
---
*This review was generated automatically by Claude AI via Amazon Bedrock*
"""
url = f'https://api.github.com/repos/{repo}/issues/{pr_number}/comments'
response = requests.post(url, headers=headers, json={'body': comment_body})
if response.status_code == 201:
print("✅ Review comment posted successfully")
else:
print(f"❌ Failed to post comment: {response.status_code}")
print(response.text)
def main():
# Read changed files
with open('changed_files.txt', 'r') as f:
changed_files = [line.strip() for line in f.readlines() if line.strip()]
# Read diff content
with open('changes.diff', 'r') as f:
diff_content = f.read()
if not diff_content.strip():
print("No changes to review")
return
print("🔍 Analyzing changes with Claude...")
review = analyze_with_claude(diff_content, changed_files)
print("📝 Posting review comment...")
post_pr_comment(review)
if __name__ == "__main__":
main()
EOF
# Set PR number for API calls
export GITHUB_PR_NUMBER=${{ github.event.number }}
python claude_review.py