Skip to content

Commit ad2fffc

Browse files
Merge pull request #7099 from continuedev/tomasz/continuous-ai-review
Continuous ai review bot
2 parents e8de12e + 9150b6f commit ad2fffc

2 files changed

Lines changed: 191 additions & 0 deletions

File tree

.github/pull_request_template.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22

33
[ What changed? Feel free to be brief. ]
44

5+
## AI Code Review
6+
7+
- **Team members only**: AI review runs automatically when PR is opened or marked ready for review
8+
- Team members can also trigger a review by commenting `@continue-review`
9+
510
## Checklist
611

712
- [] I've read the [contributing guide](https://github.com/continuedev/continue/blob/main/CONTRIBUTING.md)
Lines changed: 186 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,186 @@
1+
name: Continue CLI Code Review
2+
3+
on:
4+
pull_request:
5+
types: [opened, ready_for_review]
6+
issue_comment:
7+
types: [created]
8+
9+
permissions:
10+
contents: read
11+
pull-requests: write
12+
issues: write
13+
14+
jobs:
15+
code-review:
16+
name: AI Code 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-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-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@v4
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 PR 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 diff
59+
gh pr diff $PR_NUMBER > pr_diff.txt
60+
61+
# Create review prompt
62+
cat > review_prompt.txt << 'EOF'
63+
You are conducting a code review for a pull request. Below is the git diff showing all the changes:
64+
65+
EOF
66+
67+
echo "--- PR DIFF START ---" >> review_prompt.txt
68+
cat pr_diff.txt >> review_prompt.txt
69+
echo "--- PR DIFF END ---" >> review_prompt.txt
70+
71+
cat >> review_prompt.txt << 'EOF'
72+
73+
Please analyze these changes and provide a comprehensive code review. Consider:
74+
75+
1. **Code Quality**: Are there any bugs, performance issues, or code smells?
76+
2. **Best Practices**: Does the code follow established patterns and conventions?
77+
3. **Security**: Are there any potential security vulnerabilities?
78+
4. **Testing**: Are appropriate tests included or updated?
79+
5. **Documentation**: Is documentation adequate for the changes?
80+
6. **Architecture**: Do the changes fit well with the existing codebase structure?
81+
82+
You can use the available tools to explore the codebase and understand context better.
83+
84+
Format your response as a markdown code review with the following structure:
85+
86+
## Code Review Summary
87+
88+
### ✅ Strengths
89+
- **[Aspect]**: [Description of what was done well]
90+
91+
### ⚠️ Issues Found
92+
93+
Only include the severity subheaders below if you actually found issues at that level:
94+
95+
#### Critical
96+
- **[Issue Title]**: [Description of critical issues that must be fixed before merging]
97+
98+
#### High
99+
- **[Issue Title]**: [Description of high-priority issues that should be fixed]
100+
101+
#### Medium
102+
- **[Issue Title]**: [Description of issues that should be addressed]
103+
104+
#### Low
105+
- **[Issue Title]**: [Description of minor issues or nice-to-have improvements]
106+
107+
108+
### 💡 Suggestions
109+
- **[Suggestion Title]**: [Description of improvement recommendations]
110+
111+
### 🚀 Overall Assessment
112+
[Provide overall recommendation: APPROVE, REQUEST_CHANGES, or COMMENT]
113+
114+
Only call the 'exit' tool if you find critical security vulnerabilities or bugs that would break production.
115+
EOF
116+
env:
117+
GH_TOKEN: ${{ github.token }}
118+
119+
- name: Run Continue CLI Review
120+
run: |
121+
echo "Running Continue CLI with prompt:"
122+
echo "=================================="
123+
cat review_prompt.txt
124+
echo "=================================="
125+
echo ""
126+
127+
# Run the CLI with hardcoded assistant and pipe output to code_review.md
128+
cat review_prompt.txt | cn --readonly --org continuedev --config continuedev/review-bot -p > code_review.md
129+
env:
130+
CONTINUE_API_KEY: ${{ secrets.CONTINUE_API_KEY }}
131+
132+
- name: Upload Review Results
133+
uses: actions/upload-artifact@v4
134+
if: always()
135+
with:
136+
name: code-review-results
137+
path: |
138+
code_review.md
139+
review_prompt.txt
140+
pr_diff.txt
141+
retention-days: 30
142+
143+
- name: Comment PR with Review
144+
if: always()
145+
uses: actions/github-script@v7
146+
with:
147+
script: |
148+
const fs = require('fs');
149+
150+
try {
151+
let reviewContent = '';
152+
153+
if (fs.existsSync('code_review.md') && fs.statSync('code_review.md').size > 0) {
154+
reviewContent = fs.readFileSync('code_review.md', 'utf8');
155+
} else {
156+
reviewContent = '⚠️ AI review completed but no review output was generated. Check the action logs for details.';
157+
}
158+
159+
// Get PR number based on event type
160+
let prNumber;
161+
if (context.eventName === 'pull_request') {
162+
prNumber = context.payload.pull_request.number;
163+
} else {
164+
// For issue_comment event
165+
prNumber = context.payload.issue.number;
166+
}
167+
168+
// Add a header if triggered by comment
169+
if (context.eventName === 'issue_comment') {
170+
reviewContent = `*Triggered by @${context.payload.comment.user.login}'s request*\n\n${reviewContent}`;
171+
}
172+
173+
// Create new comment
174+
await github.rest.issues.createComment({
175+
issue_number: prNumber,
176+
owner: context.repo.owner,
177+
repo: context.repo.repo,
178+
body: reviewContent
179+
});
180+
console.log(`Successfully created new comment on PR #${prNumber}`);
181+
} catch (error) {
182+
console.log('Failed to post comment:', error.message);
183+
console.log('Error details:', error);
184+
}
185+
env:
186+
GITHUB_TOKEN: ${{ github.token }}

0 commit comments

Comments
 (0)