-
-
Notifications
You must be signed in to change notification settings - Fork 6
181 lines (158 loc) · 6.35 KB
/
coderabbit-review.yml
File metadata and controls
181 lines (158 loc) · 6.35 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
name: CodeRabbit Full Review
on:
# Manual trigger to review all open PRs or full codebase
workflow_dispatch:
inputs:
review_type:
description: 'Type of review to run'
required: true
default: 'open_prs'
type: choice
options:
- open_prs
- full_codebase
permissions:
contents: read
pull-requests: write
issues: write
jobs:
# Review all open PRs
review-open-prs:
name: Review Open PRs
if: github.event.inputs.review_type == 'open_prs'
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
- name: Get open PRs and trigger reviews
uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8
with:
script: |
const { owner, repo } = context.repo;
// Use paginator to get ALL open PRs (handles pagination automatically)
const prs = await github.paginate(github.rest.pulls.list, {
owner,
repo,
state: 'open',
per_page: 100
});
console.log(`Found ${prs.length} open PRs`);
for (const pr of prs) {
console.log(`Requesting review for PR #${pr.number}: ${pr.title}`);
// Add comment to trigger CodeRabbit review
await github.rest.issues.createComment({
owner,
repo,
issue_number: pr.number,
body: '@coderabbitai full review'
});
// Small delay to avoid rate limiting
await new Promise(r => setTimeout(r, 2000));
}
console.log('Done! CodeRabbit will review all open PRs.');
# Full codebase review (creates an issue with analysis)
full-codebase-review:
name: Full Codebase Review
if: github.event.inputs.review_type == 'full_codebase'
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
- name: Setup Node.js
uses: actions/setup-node@6044e13b5dc448c55e2357c09f80417699197238 # v6
with:
node-version: '20'
cache: 'npm'
- name: Install dependencies
run: npm ci
- name: Run ESLint
id: eslint
run: |
npm run lint -- --format json --output-file eslint-report.json || true
echo "eslint_issues=$(cat eslint-report.json | jq '[.[].messages | length] | add // 0')" >> $GITHUB_OUTPUT
continue-on-error: true
- name: Run TypeScript check
id: tsc
run: |
npx tsc --noEmit 2>&1 | tee tsc-output.txt || true
echo "tsc_errors=$(grep -c 'error TS' tsc-output.txt || echo 0)" >> $GITHUB_OUTPUT
continue-on-error: true
- name: Count lines of code
id: loc
run: |
# Handle case where no .ts files exist
FILE_COUNT=$(find src -name '*.ts' 2>/dev/null | wc -l | tr -d ' ')
if [ "$FILE_COUNT" -eq 0 ] || [ -z "$FILE_COUNT" ]; then
echo "total_lines=0" >> $GITHUB_OUTPUT
echo "file_count=0" >> $GITHUB_OUTPUT
else
TOTAL_LINES=$(find src -name '*.ts' | xargs wc -l | tail -1 | awk '{print $1}')
echo "total_lines=${TOTAL_LINES:-0}" >> $GITHUB_OUTPUT
echo "file_count=$FILE_COUNT" >> $GITHUB_OUTPUT
fi
- name: Create or update codebase analysis issue
uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8
with:
script: |
const { owner, repo } = context.repo;
const eslintIssues = '${{ steps.eslint.outputs.eslint_issues }}' || '0';
const tscErrors = '${{ steps.tsc.outputs.tsc_errors }}' || '0';
const totalLines = '${{ steps.loc.outputs.total_lines }}' || '0';
const fileCount = '${{ steps.loc.outputs.file_count }}' || '0';
const issueTitle = 'Full Codebase Review Request';
const bodyLines = [
'## Codebase Analysis Report',
'',
'@coderabbitai Please perform a comprehensive review of the entire codebase.',
'',
'### Quick Stats',
`- **TypeScript Files**: ${fileCount}`,
`- **Total Lines**: ${totalLines}`,
`- **ESLint Issues**: ${eslintIssues}`,
`- **TypeScript Errors**: ${tscErrors}`,
'',
'### Review Request',
'Please analyze:',
'1. **Architecture**: Overall code structure and patterns',
'2. **Security**: Potential vulnerabilities (OWASP top 10)',
'3. **Performance**: Bottlenecks and optimization opportunities',
'4. **Code Quality**: Maintainability, readability, best practices',
'5. **Testing**: Coverage gaps and testing strategy',
'6. **Dependencies**: Outdated or vulnerable packages',
'',
'---',
`Generated by GitHub Actions workflow on ${new Date().toISOString()}`
];
const body = bodyLines.join('\n');
// Check for existing open issue with the same title
const existingIssues = await github.rest.issues.listForRepo({
owner,
repo,
state: 'open',
labels: 'coderabbit,review',
per_page: 100
});
const existingIssue = existingIssues.data.find(
issue => issue.title === issueTitle
);
if (existingIssue) {
// Update existing issue with a comment
console.log(`Found existing issue #${existingIssue.number}, adding comment`);
await github.rest.issues.createComment({
owner,
repo,
issue_number: existingIssue.number,
body: body
});
console.log(`Updated issue #${existingIssue.number}`);
} else {
// Create new issue
const newIssue = await github.rest.issues.create({
owner,
repo,
title: issueTitle,
body,
labels: ['coderabbit', 'review']
});
console.log(`Created new issue #${newIssue.data.number}`);
}