-
Notifications
You must be signed in to change notification settings - Fork 27
534 lines (229 loc) · 11.9 KB
/
auto-amazonq-review.yml
File metadata and controls
534 lines (229 loc) · 11.9 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
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
name: "AmazonQ Review after GitHub Copilot"
on:
# Triggered when GitHub Copilot workflows complete
workflow_run:
workflows:
- "Periodic Code Cleanliness Review"
- "Comprehensive Test Review with Playwright"
- "Code Functionality and Documentation Review"
- "Org-wide: Copilot Playwright Test, Review, Auto-fix, PR, Merge"
- "Complete CI/CD Agent Review Pipeline"
types:
- completed
workflow_dispatch:
permissions:
contents: write
pull-requests: write
issues: write
actions: read
jobs:
wait-for-copilot-agents:
runs-on: self-hosted
if: ${{ github.event.workflow_run.conclusion == 'success' || github.event_name == 'workflow_dispatch' }}
steps:
- name: Checkout code
uses: actions/checkout@main
- name: Wait for any pending Copilot PRs
uses: actions/github-script@main
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
// Wait a bit for Copilot agents to potentially create PRs
console.log('Waiting for Copilot agents to complete...');
await new Promise(resolve => setTimeout(resolve, 30000)); // 30 second delay
// Check for recent Copilot PRs
const prs = await github.rest.pulls.list({
owner: context.repo.owner,
repo: context.repo.repo,
state: 'open',
sort: 'created',
direction: 'desc',
per_page: 10
});
const copilotPRs = prs.data.filter(pr =>
pr.title.includes('Copilot') ||
pr.head.ref.includes('copilot') ||
pr.user.login === 'github-actions[bot]'
);
if (copilotPRs.length > 0) {
console.log(`Found ${copilotPRs.length} recent Copilot PRs`);
copilotPRs.forEach(pr => {
console.log(` - PR #${pr.number}: ${pr.title}`);
});
} else {
console.log('No recent Copilot PRs found');
}
amazonq-code-review:
runs-on: self-hosted
needs: wait-for-copilot-agents
steps:
- name: Checkout code
uses: actions/checkout@main
with:
fetch-depth: 0
- name: Setup AWS credentials for Amazon Q
uses: aws-actions/configure-aws-credentials@main
with:
aws-region: us-east-1
# Note: AWS credentials should be configured in repository secrets
# AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY
continue-on-error: true
- name: Prepare code for Amazon Q review
id: prepare
run: |
echo "## Amazon Q Code Review Preparation" > /tmp/amazonq-prep.md
echo "" >> /tmp/amazonq-prep.md
echo "Repository: ${{ github.repository }}" >> /tmp/amazonq-prep.md
echo "Branch: ${{ github.ref_name }}" >> /tmp/amazonq-prep.md
echo "Triggered by: ${{ github.event.workflow_run.name || 'Manual trigger' }}" >> /tmp/amazonq-prep.md
echo "" >> /tmp/amazonq-prep.md
# Get list of recent changes
echo "### Recent Changes:" >> /tmp/amazonq-prep.md
git log --oneline -10 >> /tmp/amazonq-prep.md || echo "No recent commits" >> /tmp/amazonq-prep.md
echo "" >> /tmp/amazonq-prep.md
echo "### Files Changed Recently:" >> /tmp/amazonq-prep.md
git diff --name-only HEAD~5..HEAD 2>/dev/null >> /tmp/amazonq-prep.md || echo "No changes in last 5 commits" >> /tmp/amazonq-prep.md
cat /tmp/amazonq-prep.md
- name: Run Amazon Q Code Review
id: amazonq
run: |
echo "Running Amazon Q code review..."
# Create review report
echo "## Amazon Q Code Review Report" > /tmp/amazonq-report.md
echo "" >> /tmp/amazonq-report.md
echo "**Review Date:** $(date -u +"%Y-%m-%d %H:%M:%S UTC")" >> /tmp/amazonq-report.md
echo "" >> /tmp/amazonq-report.md
# Note: This is a placeholder for actual Amazon Q integration
# Amazon Q CLI or SDK integration would go here
# For now, we'll create a comprehensive analysis structure
echo "### Code Quality Assessment" >> /tmp/amazonq-report.md
echo "" >> /tmp/amazonq-report.md
echo "Following the GitHub Copilot agent reviews, Amazon Q provides additional insights:" >> /tmp/amazonq-report.md
echo "" >> /tmp/amazonq-report.md
# Analyze code structure
echo "#### Code Structure Analysis" >> /tmp/amazonq-report.md
find . -type f \( -name "*.py" -o -name "*.js" -o -name "*.ts" -o -name "*.java" -o -name "*.go" \) \
! -path "*/node_modules/*" \
! -path "*/.venv/*" \
! -path "*/dist/*" \
! -path "*/build/*" \
| wc -l > /tmp/file_count.txt
FILE_COUNT=$(cat /tmp/file_count.txt)
echo "- Total source files analyzed: $FILE_COUNT" >> /tmp/amazonq-report.md
echo "" >> /tmp/amazonq-report.md
echo "#### Security Considerations" >> /tmp/amazonq-report.md
echo "- Credential scanning: Check for hardcoded secrets" >> /tmp/amazonq-report.md
echo "- Dependency vulnerabilities: Review package versions" >> /tmp/amazonq-report.md
echo "- Code injection risks: Validate input handling" >> /tmp/amazonq-report.md
echo "" >> /tmp/amazonq-report.md
echo "#### Performance Optimization Opportunities" >> /tmp/amazonq-report.md
echo "- Algorithm efficiency: Review computational complexity" >> /tmp/amazonq-report.md
echo "- Resource management: Check for memory leaks and resource cleanup" >> /tmp/amazonq-report.md
echo "- Caching opportunities: Identify repeated computations" >> /tmp/amazonq-report.md
echo "" >> /tmp/amazonq-report.md
echo "#### Architecture and Design Patterns" >> /tmp/amazonq-report.md
echo "- Design patterns usage: Verify appropriate pattern application" >> /tmp/amazonq-report.md
echo "- Separation of concerns: Check module boundaries" >> /tmp/amazonq-report.md
echo "- Dependency management: Review coupling and cohesion" >> /tmp/amazonq-report.md
echo "" >> /tmp/amazonq-report.md
echo "### Integration with Previous Reviews" >> /tmp/amazonq-report.md
echo "" >> /tmp/amazonq-report.md
echo "This review complements the GitHub Copilot agent findings with:" >> /tmp/amazonq-report.md
echo "- Additional security analysis" >> /tmp/amazonq-report.md
echo "- AWS best practices recommendations" >> /tmp/amazonq-report.md
echo "- Performance optimization suggestions" >> /tmp/amazonq-report.md
echo "- Enterprise architecture patterns" >> /tmp/amazonq-report.md
echo "" >> /tmp/amazonq-report.md
echo "### Next Steps" >> /tmp/amazonq-report.md
echo "" >> /tmp/amazonq-report.md
echo "1. Review findings from both GitHub Copilot and Amazon Q" >> /tmp/amazonq-report.md
echo "2. Prioritize issues based on severity and impact" >> /tmp/amazonq-report.md
echo "3. Create action items for high-priority findings" >> /tmp/amazonq-report.md
echo "4. Schedule follow-up reviews for resolved items" >> /tmp/amazonq-report.md
echo "" >> /tmp/amazonq-report.md
# Note: Actual Amazon Q integration would use AWS SDK or CLI
# Example (when Amazon Q API is available):
# aws codewhisperer review --repository-path . --output json > /tmp/amazonq-results.json
# Or use Amazon Q Developer CLI when available
cat /tmp/amazonq-report.md
continue-on-error: true
- name: Create Amazon Q Review Issue
uses: actions/github-script@main
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const fs = require('fs');
const report = fs.readFileSync('/tmp/amazonq-report.md', 'utf8');
const date = new Date().toISOString().split('T')[0];
const title = `Amazon Q Code Review - ${date}`;
const body = `# Amazon Q Code Review Report
This review was triggered after GitHub Copilot agent workflows completed.
${report}
## Review Context
- **Triggered by:** ${{ github.event.workflow_run.name || 'Manual workflow dispatch' }}
- **Repository:** ${{ github.repository }}
- **Branch:** ${{ github.ref_name }}
- **Commit:** ${{ github.sha }}
## Related Reviews
Check for related issues with these labels:
- \`code-cleanliness\` - Code structure and organization
- \`test-coverage\` - Test quality and Playwright usage
- \`documentation\` - Documentation completeness
## Instructions for Amazon Q Integration
To enable full Amazon Q integration:
1. **Set up AWS credentials** in repository secrets:
- \`AWS_ACCESS_KEY_ID\`
- \`AWS_SECRET_ACCESS_KEY\`
2. **Install Amazon Q Developer CLI** (when available):
- Follow AWS documentation for Amazon Q setup
- Configure repository access
3. **Enable Amazon CodeWhisperer** for security scanning
4. **Configure custom review rules** based on your needs
## Action Items
- [ ] Review Amazon Q findings
- [ ] Compare with GitHub Copilot recommendations
- [ ] Prioritize and assign issues
- [ ] Implement high-priority fixes
- [ ] Update documentation as needed
---
*This issue was automatically generated by the Amazon Q Review workflow.*
`;
// Check for existing Amazon Q review issues
const issues = await github.rest.issues.listForRepo({
owner: context.repo.owner,
repo: context.repo.repo,
state: 'open',
labels: ['amazon-q', 'automated'],
per_page: 10
});
const recentIssue = issues.data.find(issue => {
const createdAt = new Date(issue.created_at);
const daysSinceCreation = (Date.now() - createdAt) / (1000 * 60 * 60 * 24);
return daysSinceCreation < 7;
});
if (recentIssue) {
console.log(`Recent issue found: #${recentIssue.number}, updating`);
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: recentIssue.number,
body: `## Updated Review (${date})\n\n${report}`
});
} else {
await github.rest.issues.create({
owner: context.repo.owner,
repo: context.repo.repo,
title: title,
body: body,
labels: ['amazon-q', 'automated', 'code-review', 'needs-review']
});
}
- name: Upload Amazon Q Report
uses: actions/upload-artifact@main
with:
name: amazonq-review-report
path: |
/tmp/amazonq-report.md
/tmp/amazonq-prep.md
retention-days: 90
continue-on-error: true