Elffuss BraidHub

kikocis/continue public

19cfb6ec829a · 11.9 KiBRawPermalink
1name: Continue Detailed Review
2
3on:
4 pull_request:
5 types: [opened, ready_for_review]
6 issue_comment:
7 types: [created]
8
9permissions:
10 contents: read
11 pull-requests: write
12 issues: write
13
14jobs:
15 detailed-code-review:
16 name: Continue Detailed Review
17 runs-on: ubuntu-latest
18 timeout-minutes: 10
19 # Only run if:
20 # - It's a PR event from a team member (with write/admin permissions)
21 # - OR it's a comment with @continue-detailed-review on a PR from a team member
22 if: >
23 (github.event_name == 'pull_request' &&
24 (github.event.pull_request.author_association == 'OWNER' ||
25 github.event.pull_request.author_association == 'MEMBER' ||
26 github.event.pull_request.author_association == 'COLLABORATOR')) ||
27 (github.event_name == 'issue_comment' &&
28 github.event.issue.pull_request &&
29 contains(github.event.comment.body, '@continue-detailed-review') &&
30 (github.event.comment.author_association == 'OWNER' ||
31 github.event.comment.author_association == 'MEMBER' ||
32 github.event.comment.author_association == 'COLLABORATOR'))
33
34 steps:
35 - name: Checkout Repository
36 uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
37 with:
38 fetch-depth: 0 # Fetch full history for better context
39
40 - name: Setup Node.js
41 uses: actions/setup-node@v4
42 with:
43 node-version: 20
44
45 - name: Install Continue CLI
46 run: npm install -g @continuedev/cli@1.4.25
47
48 - name: Build Inline Review Prompt
49 run: |
50 # Get PR number based on event type
51 if [ "${{ github.event_name }}" = "pull_request" ]; then
52 PR_NUMBER="${{ github.event.number }}"
53 else
54 # For issue_comment event on a PR
55 PR_NUMBER="${{ github.event.issue.number }}"
56 fi
57
58 # Get PR files with line numbers
59 gh api repos/${{ github.repository }}/pulls/$PR_NUMBER/files > pr_files.json
60
61 # Get PR diff with context
62 gh pr diff $PR_NUMBER --color=never > pr_diff.txt
63
64 # Annotate diff with position numbers for easy reference
65 awk '
66 /^@@/ {
67 pos = 0
68 print
69 next
70 }
71 /^diff --git/ || /^index / || /^--- / || /^\+\+\+ / {
72 print
73 next
74 }
75 {
76 pos++
77 printf "[POS:%d] %s\n", pos, $0
78 }
79 ' pr_diff.txt > pr_diff_annotated.txt
80
81 # Create review prompt for inline comments
82 cat > inline_review_prompt.txt << 'EOF'
83 You are conducting a detailed inline code review for a pull request.
84
85 Your task is to analyze the code changes and generate specific, actionable review comments for individual lines or small sections of code.
86
87 IMPORTANT: The diff below has been annotated with [POS:N] markers showing the exact position for each line.
88
89 Example of how to use the position markers:
90 ```
91 diff --git a/src/app.js b/src/app.js
92 index abc123..def456 100644
93 --- a/src/app.js
94 +++ b/src/app.js
95 @@ -10,4 +10,6 @@ function example() {
96 [POS:1] console.log("context");
97 [POS:2] - const old = "remove this";
98 [POS:3] + const new = "add this";
99 [POS:4] + const risky = eval(userInput); <-- To comment here, use position: 4
100 [POS:5] return result;
101 [POS:6] + console.log("done");
102 @@ -20,3 +22,4 @@ function another() {
103 [POS:1] let x = 1;
104 [POS:2] + let y = 2; <-- To comment here, use position: 2
105 ```
106
107 To comment on a line, simply use the number from its [POS:N] marker as the position value.
108 For example: {"path": "src/app.js", "position": 4, "body": "Avoid using eval with user input"}
109
110 Below is the annotated PR diff:
111
112 EOF
113
114 cat pr_diff_annotated.txt >> inline_review_prompt.txt
115
116 cat >> inline_review_prompt.txt << 'EOF'
117
118 Please analyze these changes and provide inline review comments in the following JSON format:
119
120 {
121 "review_summary": "Overall assessment of the PR",
122 "comments": [
123 {
124 "path": "path/to/file.js",
125 "position": 4,
126 "body": "Brief, specific comment about this line or section"
127 }
128 ]
129 }
130
131 Focus on:
132 1. **Critical Issues**: Security vulnerabilities, bugs that will break functionality
133 2. **High Priority**: Performance problems, incorrect logic, missing error handling
134 3. **Medium Priority**: Code style violations, potential edge cases, unclear code
135 4. **Low Priority**: Suggestions for improvement, refactoring opportunities
136
137 Guidelines for comments:
138 - Be specific and actionable
139 - Use the [POS:N] number shown in the diff as the position value
140 - Keep comments concise but informative
141 - Suggest concrete improvements when pointing out issues
142 - Only comment on actual problems or important improvements
143
144 Important:
145 - Output ONLY valid JSON, no additional text
146 - Use the exact number from [POS:N] markers as the position
147 - Only comment on changed lines (lines with + or - prefix)
148 - Comment on the most important issues first
149 - Limit to maximum 20 most relevant comments
150 EOF
151 env:
152 GH_TOKEN: ${{ github.token }}
153
154 - name: Run Continue CLI Inline Review
155 run: |
156 echo "Running Continue CLI for inline review..."
157
158 # Log the prompt for debugging
159 echo "===== START REVIEW PROMPT ====="
160 head -n 50 inline_review_prompt.txt
161 echo "... [diff content] ..."
162 tail -n 20 inline_review_prompt.txt
163 echo "===== END REVIEW PROMPT ====="
164
165 # Run the CLI and capture JSON output
166 cat inline_review_prompt.txt | cn --readonly --format json --org continuedev --config continuedev/review-bot -p > inline_review_raw.json
167
168 # Log the output for debugging
169 echo "Initial Continue CLI output:"
170 cat inline_review_raw.json
171
172 # Validate JSON output
173 if ! jq empty inline_review_raw.json 2>/dev/null; then
174 echo "Invalid JSON output from Continue CLI"
175 echo "{\"review_summary\": \"Failed to generate review\", \"comments\": []}" > inline_review.json
176 else
177 # Use the output directly since positions are already correct
178 cp inline_review_raw.json inline_review.json
179 echo "Review output:"
180 cat inline_review.json
181 fi
182 env:
183 CONTINUE_API_KEY: ${{ secrets.CONTINUE_API_KEY }}
184
185 - name: Post Inline Review Comments
186 uses: actions/github-script@v7
187 with:
188 script: |
189 const fs = require('fs');
190
191 try {
192 // Read the review output
193 let reviewData;
194 try {
195 const reviewContent = fs.readFileSync('inline_review.json', 'utf8');
196 reviewData = JSON.parse(reviewContent);
197 } catch (parseError) {
198 console.log('Failed to parse review JSON:', parseError);
199 reviewData = {
200 review_summary: 'AI review completed but failed to parse output',
201 comments: []
202 };
203 }
204
205 // Get PR number
206 let prNumber;
207 if (context.eventName === 'pull_request') {
208 prNumber = context.payload.pull_request.number;
209 } else {
210 prNumber = context.payload.issue.number;
211 }
212
213 // Get the latest commit SHA
214 const { data: pr } = await github.rest.pulls.get({
215 owner: context.repo.owner,
216 repo: context.repo.repo,
217 pull_number: prNumber
218 });
219
220 const commitSha = pr.head.sha;
221
222 // Prepare review comments - filter out comments without required fields
223 const allComments = reviewData.comments || [];
224 const validComments = allComments.filter(comment =>
225 comment.position &&
226 comment.path &&
227 comment.body &&
228 typeof comment.position === 'number' &&
229 comment.position > 0
230 );
231
232 if (validComments.length < allComments.length) {
233 console.log(`Filtered out ${allComments.length - validComments.length} comments due to missing/invalid position, path, or body`);
234 const invalidComments = allComments.filter(c => !validComments.includes(c));
235 console.log('Invalid comments:', JSON.stringify(invalidComments, null, 2));
236 }
237
238 const comments = validComments.map(comment => ({
239 path: comment.path,
240 position: comment.position,
241 body: comment.body
242 }));
243
244 // Create the review
245 if (comments.length > 0) {
246 try {
247 await github.rest.pulls.createReview({
248 owner: context.repo.owner,
249 repo: context.repo.repo,
250 pull_number: prNumber,
251 commit_id: commitSha,
252 body: reviewData.review_summary || 'AI Code Review',
253 event: 'COMMENT',
254 comments: comments
255 });
256 console.log(`Successfully created review with ${comments.length} inline comments`);
257 } catch (reviewError) {
258 console.log('Failed to create review:', reviewError.message);
259
260 // Fallback: post as a regular comment if review creation fails
261 const fallbackBody = `## AI Code Review\n\n${reviewData.review_summary}\n\n` +
262 `*Failed to post ${comments.length} inline comments. Please review the changes manually.*`;
263
264 await github.rest.issues.createComment({
265 issue_number: prNumber,
266 owner: context.repo.owner,
267 repo: context.repo.repo,
268 body: fallbackBody
269 });
270 }
271 } else {
272 // No inline comments, just post the summary
273 await github.rest.issues.createComment({
274 issue_number: prNumber,
275 owner: context.repo.owner,
276 repo: context.repo.repo,
277 body: `## AI Code Review\n\n${reviewData.review_summary}\n\n*No specific line comments generated.*`
278 });
279 }
280
281 // Add triggered by note if from comment
282 if (context.eventName === 'issue_comment') {
283 await github.rest.issues.createComment({
284 issue_number: prNumber,
285 owner: context.repo.owner,
286 repo: context.repo.repo,
287 body: `*Inline review triggered by @${context.payload.comment.user.login}*`
288 });
289 }
290
291 } catch (error) {
292 console.log('Failed to post review:', error.message);
293 console.log('Error details:', error);
294 }
295 env:
296 GITHUB_TOKEN: ${{ github.token }}
297
298 - name: Upload Review Artifacts
299 uses: actions/upload-artifact@v4
300 if: always()
301 with:
302 name: inline-review-results
303 path: |
304 inline_review_raw.json
305 inline_review.json
306 inline_review_prompt.txt
307 pr_files.json
308 pr_diff.txt
309 pr_diff_annotated.txt
310 retention-days: 7