-
Notifications
You must be signed in to change notification settings - Fork 2
185 lines (159 loc) · 5.88 KB
/
code-review.yml
File metadata and controls
185 lines (159 loc) · 5.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
name: AI Code Review
on:
pull_request:
types: [opened, synchronize, reopened]
paths:
- '**.py'
- '**.js'
- '**.ts'
- '**.java'
- '**.go'
- '**.rs'
jobs:
ai-code-review:
runs-on: ubuntu-latest
permissions:
contents: read
pull-requests: write
statuses: write
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.11'
- name: Cache dependencies
uses: actions/cache@v3
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }}
restore-keys: |
${{ runner.os }}-pip-
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
- name: Get changed files
id: changed-files
uses: tj-actions/changed-files@v40
with:
files: |
**.py
**.js
**.ts
**.java
**.go
**.rs
- name: Run AI Code Review
id: review
env:
GOOGLE_AI_API_KEY: ${{ secrets.GOOGLE_AI_API_KEY }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
PR_NUMBER: ${{ github.event.pull_request.number }}
GITHUB_REPOSITORY: ${{ github.repository }}
run: |
python -c "
import os
import sys
from pathlib import Path
# Add project to path
sys.path.insert(0, str(Path.cwd()))
from main import CodeReviewOrchestrator
from utils.github_integration import github_integration
from utils.report_generator import report_generator
# Get changed files
changed_files = '''${{ steps.changed-files.outputs.all_changed_files }}'''.split()
if not changed_files:
print('No relevant files changed')
sys.exit(0)
# Initialize orchestrator
orchestrator = CodeReviewOrchestrator()
# Review each file
all_results = []
for filepath in changed_files:
if not Path(filepath).exists():
continue
print(f'Reviewing {filepath}...')
code = Path(filepath).read_text()
# Detect language
ext = Path(filepath).suffix
lang_map = {
'.py': 'python',
'.js': 'javascript',
'.ts': 'typescript',
'.java': 'java',
'.go': 'go',
'.rs': 'rust'
}
language = lang_map.get(ext, 'python')
# Run review
results = orchestrator.review_code(code, language)
results['filepath'] = filepath
all_results.append(results)
# Generate combined report
combined_results = {
'session_id': 'github-actions',
'timestamp': all_results[0]['timestamp'] if all_results else '',
'language': 'multiple',
'summary': {
'total_agents': 3,
'successful_agents': 3,
'issues_found': sum(r.get('summary', {}).get('issues_found', 0) for r in all_results),
'recommendations_count': sum(r.get('summary', {}).get('recommendations_count', 0) for r in all_results)
},
'agents': {},
'files_reviewed': len(all_results)
}
# Post to GitHub
pr_number = int(os.getenv('PR_NUMBER', 0))
repo_name = os.getenv('GITHUB_REPOSITORY', '')
if pr_number and repo_name and github_integration.is_available():
github_integration.post_review_comment(repo_name, pr_number, combined_results)
print(f'Posted review to PR #{pr_number}')
else:
# Just print results
markdown = report_generator.generate_markdown_report(combined_results)
print('\\n' + markdown)
# Set outputs
from utils.github_integration import GitHubActionsHelper
GitHubActionsHelper.set_output('issues_count', str(combined_results['summary']['issues_found']))
GitHubActionsHelper.set_output('quality_score', '90') # Default
"
- name: Upload review report
uses: actions/upload-artifact@v3
with:
name: code-review-report
path: |
review_results_*.json
*.html
- name: Set commit status
if: always()
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
issues_count=${{ steps.review.outputs.issues_count || '0' }}
if [ "$issues_count" -le 2 ]; then
state="success"
description="Code review passed with $issues_count minor issues"
elif [ "$issues_count" -le 5 ]; then
state="success"
description="Code review completed with $issues_count issues"
else
state="failure"
description="Code review found $issues_count issues requiring attention"
fi
echo "Setting status: $state - $description"
- name: Comment on PR
if: failure()
uses: actions/github-script@v7
with:
script: |
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: '❌ AI Code Review failed. Please check the action logs for details.'
})