-
Notifications
You must be signed in to change notification settings - Fork 4.5k
233 lines (197 loc) · 7.8 KB
/
code-review-debug.yml
File metadata and controls
233 lines (197 loc) · 7.8 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
name: Continue Code Review (Debug)
on:
pull_request:
types: [opened, synchronize, ready_for_review]
issue_comment:
types: [created]
permissions:
contents: read
pull-requests: write
issues: write
jobs:
review:
if: |
github.event_name == 'pull_request' ||
(github.event_name == 'issue_comment' &&
github.event.issue.pull_request &&
contains(github.event.comment.body, '@review-bot'))
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Generate App Token (Optional)
if: vars.CONTINUE_APP_ID != '' && secrets.CONTINUE_APP_PRIVATE_KEY != ''
id: generate_token
uses: actions/create-github-app-token@v1
with:
app-id: ${{ vars.CONTINUE_APP_ID }}
private-key: ${{ secrets.CONTINUE_APP_PRIVATE_KEY }}
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
- name: Validate Continue API Key
run: |
echo "🔍 Checking if CONTINUE_API_KEY is set..."
if [ -z "${{ secrets.CONTINUE_API_KEY }}" ]; then
echo "❌ ERROR: CONTINUE_API_KEY secret is not set!"
echo "Please add it in Settings → Secrets and variables → Actions"
echo "Get your key from: https://hub.continue.dev/settings/api-keys"
exit 1
else
echo "✅ CONTINUE_API_KEY is set (length: ${#CONTINUE_API_KEY})"
fi
env:
CONTINUE_API_KEY: ${{ secrets.CONTINUE_API_KEY }}
- name: Install Continue CLI
run: |
echo "📦 Installing Continue CLI..."
npm i -g @continuedev/cli
echo "✅ Continue CLI installed"
echo "🔍 Checking Continue CLI version..."
cn --version || echo "⚠️ Warning: Could not get CLI version"
- name: Verify Continue CLI Installation
run: |
echo "🔍 Verifying Continue CLI installation..."
which cn || echo "❌ ERROR: cn command not found in PATH"
cn --help || echo "❌ ERROR: cn --help failed"
- name: Get PR Details
id: pr
env:
GH_TOKEN: ${{ steps.generate_token.outputs.token || github.token }}
run: |
echo "🔍 Getting PR details..."
if [ "${{ github.event_name }}" = "issue_comment" ]; then
PR_NUMBER=$(jq -r .issue.number "$GITHUB_EVENT_PATH")
else
PR_NUMBER=$(jq -r .pull_request.number "$GITHUB_EVENT_PATH")
fi
echo "PR_NUMBER=$PR_NUMBER" >> $GITHUB_OUTPUT
echo "✅ PR Number: $PR_NUMBER"
echo "📥 Fetching PR diff..."
gh pr diff $PR_NUMBER > pr.diff || {
echo "❌ ERROR: Failed to fetch PR diff"
exit 1
}
echo "✅ PR diff saved ($(wc -l < pr.diff) lines)"
echo "📁 Fetching changed files..."
gh pr view $PR_NUMBER --json files -q '.files[].path' > changed_files.txt || {
echo "❌ ERROR: Failed to fetch changed files"
exit 1
}
echo "✅ Changed files saved ($(wc -l < changed_files.txt) files)"
echo "📋 Changed files:"
cat changed_files.txt
- name: Check for Custom Rules
run: |
echo "🔍 Checking for custom rules in .continue/rules/..."
if [ -d ".continue/rules" ]; then
echo "✅ Found .continue/rules directory"
echo "📋 Custom rules:"
find .continue/rules -name "*.md" -o -name "*.txt" || echo "No rule files found"
else
echo "ℹ️ No custom rules directory found (this is optional)"
fi
- name: Run Continue Review
env:
CONTINUE_API_KEY: ${{ secrets.CONTINUE_API_KEY }}
run: |
echo "🤖 Running Continue code review..."
CHANGED_FILES=$(cat changed_files.txt | tr '\n' ' ')
DIFF=$(cat pr.diff)
# Check if running from issue comment
if [ "${{ github.event_name }}" = "issue_comment" ]; then
COMMENT_BODY="${{ github.event.comment.body }}"
CUSTOM_REQUEST=$(echo "$COMMENT_BODY" | sed -n 's/.*@review-bot check for \(.*\)/\1/p')
if [ -n "$CUSTOM_REQUEST" ]; then
echo "📝 Custom review request: $CUSTOM_REQUEST"
FOCUS="Focus specifically on: $CUSTOM_REQUEST"
fi
fi
PROMPT="You are an expert code reviewer. Review the following pull request changes.
Changed files:
$CHANGED_FILES
Diff:
\`\`\`diff
$DIFF
\`\`\`
${FOCUS:-Review the code for potential issues, bugs, security concerns, and improvements.}
Provide your review in the following markdown format:
## Summary
Brief overview of the changes
## Key Findings
- List any issues, bugs, or security concerns
- Suggest improvements
## Positive Observations
- Note good practices
## Recommendations
- Actionable suggestions"
echo "🔍 Prompt length: ${#PROMPT} characters"
echo "🔍 Running: cn --config continuedev/code-reviewer -p \"...\" --auto"
cn --config continuedev/code-reviewer \
-p "$PROMPT" \
--auto > review_output.md 2>&1 || {
EXIT_CODE=$?
echo "❌ ERROR: Continue review failed with exit code $EXIT_CODE"
echo "📋 Output:"
cat review_output.md
echo ""
echo "🔍 Debugging information:"
echo " - Continue API Key length: ${#CONTINUE_API_KEY}"
echo " - Config: continuedev/code-reviewer"
echo " - Prompt length: ${#PROMPT}"
echo ""
echo "💡 Common issues:"
echo " 1. Invalid or expired CONTINUE_API_KEY"
echo " 2. Assistant 'continuedev/code-reviewer' not found or not accessible"
echo " 3. Continue Hub account issues"
echo ""
echo "🔧 Troubleshooting steps:"
echo " 1. Verify your API key at https://hub.continue.dev/settings/api-keys"
echo " 2. Check that you have access to the code-reviewer assistant"
echo " 3. Try creating a custom assistant for code reviews"
exit $EXIT_CODE
}
echo "✅ Review completed successfully"
echo "📋 Review output:"
cat review_output.md
- name: Post Review Comment
env:
GH_TOKEN: ${{ steps.generate_token.outputs.token || github.token }}
run: |
echo "💬 Posting review comment..."
PR_NUMBER="${{ steps.pr.outputs.PR_NUMBER }}"
REVIEW_BODY=$(cat review_output.md)
COMMENT_BODY="## 🤖 AI Code Review
$REVIEW_BODY
---
*Powered by Continue • Need a focused review? Comment \`@review-bot check for [specific concern]\`*"
# Check for existing review comment
EXISTING_COMMENT=$(gh api \
repos/${{ github.repository }}/issues/$PR_NUMBER/comments \
--jq '.[] | select(.body | contains("🤖 AI Code Review")) | .id' \
| head -n 1)
if [ -n "$EXISTING_COMMENT" ]; then
echo "🔄 Updating existing comment (ID: $EXISTING_COMMENT)..."
gh api \
--method PATCH \
repos/${{ github.repository }}/issues/comments/$EXISTING_COMMENT \
-f body="$COMMENT_BODY"
echo "✅ Comment updated"
else
echo "✨ Creating new comment..."
gh pr comment $PR_NUMBER --body "$COMMENT_BODY"
echo "✅ Comment created"
fi
- name: Upload Artifacts (Debug)
if: always()
uses: actions/upload-artifact@v4
with:
name: review-debug-artifacts
path: |
pr.diff
changed_files.txt
review_output.md
retention-days: 7