Elffuss BraidHub

kikocis/continue public

Merge pull request #7149 from continuedev/tomasz/con-3480

feat: reusable github action
Changesetaae379894b54e970d17b986ae9ca48498045ff7f604b0d11853fe7df0925beb7
AuthorTomasz Stefaniak <tomasz.p.stefaniak@gmail.com> · 2025-08-15 13:51 -07:00
CommitterGitHub <noreply@github.com> · 2025-08-15 13:51 -07:00
Parentsfdb30f09b9b2, be506e21f0b1

Browse the files at this changeset

9 files changed

modified .github/workflows/continue-detailed-review.yaml +6 −291
@@ -16,295 +16,10 @@
1616 name: Continue Detailed Review
1717 runs-on: ubuntu-latest
1818 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-
3419 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
20+ - name: Run Detailed PR Review
21+ uses: continuedev/continue/actions/detailed-review@23d9260536372acf4eb57a41e6ab62bc5869b070
22+ with:
23+ continue-api-key: ${{ secrets.CONTINUE_API_KEY }}
24+ continue-org: continuedev
25+ continue-config: continuedev/review-bot
modified .github/workflows/continue-general-review.yaml +6 −167
@@ -16,171 +16,10 @@
1616 name: Continue General Review
1717 runs-on: ubuntu-latest
1818 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-general-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-general-review') &&
30- (github.event.comment.author_association == 'OWNER' ||
31- github.event.comment.author_association == 'MEMBER' ||
32- github.event.comment.author_association == 'COLLABORATOR'))
33-
3419 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 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 }}
20+ - name: Run Continue PR Review Action
21+ uses: continuedev/continue/actions/general-review@23d9260536372acf4eb57a41e6ab62bc5869b070
22+ with:
23+ continue-api-key: ${{ secrets.CONTINUE_API_KEY }}
24+ continue-org: "continuedev"
25+ continue-config: "continuedev/review-bot"
modified .github/workflows/pr-checks.yaml +27 −0
@@ -312,6 +312,32 @@
312312
313313 # GitHub does not have a way of requiring that all checks pass (you must manually select each job)
314314 # This action at least lets us manage the list of required tests via source control
315+ pr-review-action-tests:
316+ runs-on: ubuntu-latest
317+ steps:
318+ - uses: actions/checkout@v5
319+ - uses: actions/setup-node@v4
320+ with:
321+ node-version: 20
322+
323+ - name: Cache PR review action node modules
324+ uses: actions/cache@v4
325+ id: pr-review-cache
326+ with:
327+ path: actions/detailed-review/node_modules
328+ key: ${{ runner.os }}-pr-review-action-${{ hashFiles('actions/detailed-review/package.json') }}
329+
330+ - name: Install dependencies
331+ if: steps.pr-review-cache.outputs.cache-hit != 'true'
332+ run: |
333+ cd actions/detailed-review
334+ npm install
335+
336+ - name: Run tests
337+ run: |
338+ cd actions/detailed-review
339+ npm test
340+
315341 # so that creators of new jobs can add them to this list
316342 require-all-checks-to-pass:
317343 if: always()
@@ -328,6 +354,7 @@
328354 - vscode-package-extension-linux
329355 - vscode-e2e-tests
330356 - jetbrains-tests
357+ - pr-review-action-tests
331358
332359 steps:
333360 - name: Decide whether the needed jobs succeeded or failed
added actions/README.md +251 −0
@@ -0,0 +1,251 @@
1+# Continue PR Review Actions
2+
3+GitHub Actions that provide automated code reviews for pull requests using Continue CLI.
4+
5+## Available Actions
6+
7+This repository provides two GitHub Actions for different review styles:
8+
9+### 1. General Review Action
10+
11+Provides high-level PR assessment with overall feedback and recommendations.
12+
13+- **Path:** `continuedev/continue/actions/general-review@<commit-sha>`
14+- **Trigger:** `@continue-general-review`
15+- **Output:** Summary comment with strengths, issues, and recommendations
16+
17+### 2. Detailed Review Action
18+
19+Provides line-by-line inline comments on specific code changes.
20+
21+- **Path:** `continuedev/continue/actions/detailed-review@<commit-sha>`
22+- **Trigger:** `@continue-detailed-review`
23+- **Output:** Inline review comments on specific lines of code
24+
25+## Quick Start
26+
27+### Using Both Actions Together
28+
29+```yaml
30+name: PR Reviews
31+on:
32+ pull_request:
33+ types: [opened, ready_for_review]
34+ issue_comment:
35+ types: [created]
36+
37+permissions:
38+ contents: read
39+ pull-requests: write
40+ issues: write
41+
42+jobs:
43+ general-review:
44+ runs-on: ubuntu-latest
45+ timeout-minutes: 10
46+ steps:
47+ - uses: continuedev/continue/actions/general-review@<commit-sha>
48+ with:
49+ continue-api-key: ${{ secrets.CONTINUE_API_KEY }}
50+ continue-org: "your-org-name"
51+ continue-config: "your-org-name/review-bot"
52+
53+ detailed-review:
54+ runs-on: ubuntu-latest
55+ timeout-minutes: 10
56+ steps:
57+ - uses: continuedev/continue/actions/detailed-review@<commit-sha>
58+ with:
59+ continue-api-key: ${{ secrets.CONTINUE_API_KEY }}
60+ continue-org: "your-org-name"
61+ continue-config: "your-org-name/review-bot"
62+```
63+
64+### General Review Only
65+
66+```yaml
67+name: PR General Review
68+on:
69+ pull_request:
70+ types: [opened, ready_for_review]
71+ issue_comment:
72+ types: [created]
73+
74+permissions:
75+ contents: read
76+ pull-requests: write
77+ issues: write
78+
79+jobs:
80+ review:
81+ runs-on: ubuntu-latest
82+ timeout-minutes: 10
83+ steps:
84+ - uses: continuedev/continue/actions/general-review@<commit-sha>
85+ with:
86+ continue-api-key: ${{ secrets.CONTINUE_API_KEY }}
87+ continue-org: "your-org-name"
88+ continue-config: "your-org-name/review-bot"
89+```
90+
91+### Detailed Review Only
92+
93+```yaml
94+name: PR Detailed Review
95+on:
96+ pull_request:
97+ types: [opened, ready_for_review]
98+ issue_comment:
99+ types: [created]
100+
101+permissions:
102+ contents: read
103+ pull-requests: write
104+ issues: write
105+
106+jobs:
107+ review:
108+ runs-on: ubuntu-latest
109+ timeout-minutes: 10
110+ steps:
111+ - uses: continuedev/continue/actions/detailed-review@<commit-sha>
112+ with:
113+ continue-api-key: ${{ secrets.CONTINUE_API_KEY }}
114+ continue-org: "your-org-name"
115+ continue-config: "your-org-name/review-bot"
116+```
117+
118+## Inputs
119+
120+Both actions accept the same inputs:
121+
122+| Input | Description | Required |
123+| ------------------ | -------------------------------------- | -------- |
124+| `continue-api-key` | API key for Continue service | Yes |
125+| `continue-org` | Organization for Continue config | Yes |
126+| `continue-config` | Config path (e.g., "myorg/review-bot") | Yes |
127+
128+## Setup Requirements
129+
130+### 1. Continue API Key
131+
132+Add your Continue API key as a secret named `CONTINUE_API_KEY` in your repository:
133+
134+1. Go to your repository's Settings
135+2. Navigate to Secrets and variables → Actions
136+3. Click "New repository secret"
137+4. Name: `CONTINUE_API_KEY`
138+5. Value: Your Continue API key
139+
140+### 2. Continue Configuration
141+
142+Set up your review bot configuration in Continue:
143+
144+1. Create a configuration for your organization
145+2. Configure the review bot settings
146+3. Note your organization name and config path
147+
148+### 3. Workflow Permissions
149+
150+The workflow requires these permissions:
151+
152+- `contents: read` - To checkout and read repository code
153+- `pull-requests: write` - To post review comments on PRs
154+- `issues: write` - To respond to comment triggers
155+
156+## Triggering Reviews
157+
158+Both actions can be triggered in two ways:
159+
160+### Automatic Triggers
161+
162+- When a PR is opened by a team member (OWNER, MEMBER, or COLLABORATOR)
163+- When a PR is marked as "ready for review" by a team member
164+
165+### Manual Triggers
166+
167+Team members can trigger reviews by commenting on any pull request:
168+
169+- `@continue-general-review` - Triggers a general review
170+- `@continue-detailed-review` - Triggers a detailed inline review
171+
172+## Review Outputs
173+
174+### General Review Output
175+
176+The general review provides a structured comment that includes:
177+
178+- **Strengths**: What was done well in the PR
179+- **Issues Found**: Categorized by severity (Critical, High, Medium, Low)
180+- **Suggestions**: Improvement recommendations
181+- **Overall Assessment**: Final recommendation (APPROVE, REQUEST_CHANGES, or COMMENT)
182+
183+### Detailed Review Output
184+
185+The detailed review provides:
186+
187+- **Inline Comments**: Specific feedback on individual lines of code
188+- **Position Markers**: Comments appear directly on the changed lines
189+- **Review Summary**: Overall assessment of the changes
190+- **Actionable Feedback**: Specific suggestions for each issue found
191+
192+## How It Works
193+
194+### General Review Process
195+
196+1. Checks out repository code
197+2. Fetches PR diff using GitHub CLI
198+3. Generates a comprehensive review prompt
199+4. Runs Continue CLI with specified configuration
200+5. Posts review as a PR comment
201+
202+### Detailed Review Process
203+
204+1. Checks out repository code
205+2. Fetches PR diff with GitHub API positions
206+3. Annotates diff with position markers
207+4. Generates inline review prompt
208+5. Runs Continue CLI for detailed analysis
209+6. Posts inline comments using GitHub's review API
210+
211+## Versioning
212+
213+We recommend using a specific commit SHA for stability and predictability:
214+
215+- `@<commit-sha>` - Pins to a specific commit for maximum stability (recommended)
216+- `@main` - Uses the latest code from the main branch (for bleeding edge)
217+- `@v1` - Uses a version tag when available
218+
219+Example:
220+
221+```yaml
222+uses: continuedev/continue/actions/general-review@17fe39cc4f1760838ce4428aad0a984af13f8266
223+```
224+
225+## Troubleshooting
226+
227+### Review not triggering
228+
229+- Ensure the PR author or commenter has appropriate permissions (OWNER, MEMBER, or COLLABORATOR)
230+- Check that the workflow file is in the default branch
231+- Verify the Continue API key is correctly set as a repository secret
232+
233+### No review output generated
234+
235+- Check the action logs for any errors
236+- Verify your Continue configuration is correct
237+- Ensure your Continue API key is valid
238+
239+### Inline comments not appearing (Detailed Review)
240+
241+- Check that the PR has a valid diff
242+- Verify GitHub API permissions are correct
243+- Review action logs for position calculation errors
244+
245+## Support
246+
247+For issues or questions:
248+
249+- [Continue Documentation](https://docs.continue.dev)
250+- [GitHub Issues](https://github.com/continuedev/continue/issues)
251+- [Discord Community](https://discord.gg/vapESyrFmJ)
added actions/detailed-review/action.yml +350 −0
@@ -0,0 +1,350 @@
1+name: 'Continue Detailed PR Review'
2+description: 'Automated inline code review for pull requests using Continue CLI'
3+author: 'Continue Dev, Inc.'
4+
5+inputs:
6+ continue-api-key:
7+ description: 'API key for Continue service'
8+ required: true
9+ continue-org:
10+ description: 'Organization for Continue config'
11+ required: true
12+ continue-config:
13+ description: 'Config path to use (e.g., "myorg/review-bot")'
14+ required: true
15+
16+runs:
17+ using: 'composite'
18+ steps:
19+ - name: Checkout Repository
20+ uses: actions/checkout@v4
21+
22+ - name: Check Authorization
23+ shell: bash
24+ env:
25+ # Only move the dangerous check to env to prevent shell injection
26+ HAS_TRIGGER_PHRASE: ${{ contains(github.event.comment.body, '@continue-detailed-review') }}
27+ run: |
28+ # Check if this action should run based on event type and user permissions
29+ SHOULD_RUN="false"
30+
31+ if [ "${{ github.event_name }}" = "pull_request" ]; then
32+ # Check PR author association
33+ AUTHOR_ASSOC="${{ github.event.pull_request.author_association }}"
34+ if [ "$AUTHOR_ASSOC" = "OWNER" ] || [ "$AUTHOR_ASSOC" = "MEMBER" ] || [ "$AUTHOR_ASSOC" = "COLLABORATOR" ]; then
35+ SHOULD_RUN="true"
36+ else
37+ echo "::notice::Skipping review - PR author is not a team member (association: $AUTHOR_ASSOC)"
38+ fi
39+ elif [ "${{ github.event_name }}" = "issue_comment" ]; then
40+ # Check if it's a PR comment with the trigger phrase
41+ if [ "${{ github.event.issue.pull_request }}" != "" ] && [ "$HAS_TRIGGER_PHRASE" = "true" ]; then
42+ COMMENTER_ASSOC="${{ github.event.comment.author_association }}"
43+ if [ "$COMMENTER_ASSOC" = "OWNER" ] || [ "$COMMENTER_ASSOC" = "MEMBER" ] || [ "$COMMENTER_ASSOC" = "COLLABORATOR" ]; then
44+ SHOULD_RUN="true"
45+ else
46+ echo "::notice::Skipping review - Commenter is not a team member (association: $COMMENTER_ASSOC)"
47+ fi
48+ else
49+ echo "::notice::Skipping review - Comment does not contain @continue-detailed-review trigger, or is not on a PR"
50+ fi
51+ else
52+ echo "::notice::Skipping review - Event type ${{ github.event_name }} is not supported"
53+ fi
54+
55+ if [ "$SHOULD_RUN" != "true" ]; then
56+ echo "SKIP_REVIEW=true" >> $GITHUB_ENV
57+ exit 0
58+ fi
59+
60+ echo "SKIP_REVIEW=false" >> $GITHUB_ENV
61+
62+ - name: Setup Node.js
63+ if: env.SKIP_REVIEW != 'true'
64+ uses: actions/setup-node@v4
65+ with:
66+ node-version: 20
67+
68+ - name: Install Continue CLI
69+ if: env.SKIP_REVIEW != 'true'
70+ shell: bash
71+ run: npm install -g @continuedev/cli@1.4.25
72+
73+ - name: Build Inline Review Prompt
74+ if: env.SKIP_REVIEW != 'true'
75+ shell: bash
76+ env:
77+ GH_TOKEN: ${{ github.token }}
78+ run: |
79+ # Get PR number based on event type
80+ if [ "${{ github.event_name }}" = "pull_request" ]; then
81+ PR_NUMBER="${{ github.event.number }}"
82+ else
83+ # For issue_comment event on a PR
84+ PR_NUMBER="${{ github.event.issue.number }}"
85+ fi
86+
87+ # Get PR files with line numbers
88+ gh api repos/${{ github.repository }}/pulls/$PR_NUMBER/files > pr_files.json
89+
90+ # Get PR diff with context
91+ gh pr diff $PR_NUMBER --color=never > pr_diff.txt
92+
93+ # Annotate diff with GitHub API positions
94+ node ${{ github.action_path }}/annotate-diff.js pr_diff.txt > pr_diff_annotated.txt
95+
96+ # Debug: Show sample of annotated diff
97+ echo "=== SAMPLE OF ANNOTATED DIFF ==="
98+ head -100 pr_diff_annotated.txt | grep -E "^\[POS:|^@@|^diff --git" || head -50 pr_diff_annotated.txt
99+ echo "=== END SAMPLE ==="
100+
101+ # Create review prompt for inline comments
102+ cat > inline_review_prompt.txt << 'EOF'
103+ You are conducting a detailed inline code review for a pull request.
104+
105+ Your task is to analyze the code changes and generate specific, actionable review comments for individual lines or small sections of code.
106+
107+ IMPORTANT: The diff below has been annotated with [POS:N] markers showing the exact position for each line.
108+
109+ Example of how to use the position markers:
110+ ```
111+ diff --git a/src/app.js b/src/app.js
112+ index abc123..def456 100644
113+ --- a/src/app.js
114+ +++ b/src/app.js
115+ @@ -10,4 +10,6 @@ function example() {
116+ [POS:1] console.log("context");
117+ [POS:2] - const old = "remove this";
118+ [POS:3] + const new = "add this";
119+ [POS:4] + const risky = eval(userInput); <-- To comment here, use position: 4
120+ [POS:5] return result;
121+ [POS:6] + console.log("done");
122+ @@ -20,3 +22,4 @@ function another() {
123+ [POS:1] let x = 1;
124+ [POS:2] + let y = 2; <-- To comment here, use position: 2
125+ ```
126+
127+ To comment on a line, simply use the number from its [POS:N] marker as the position value.
128+ For example: {"path": "src/app.js", "position": 4, "body": "Avoid using eval with user input"}
129+
130+ Below is the annotated PR diff:
131+
132+ EOF
133+
134+ cat pr_diff_annotated.txt >> inline_review_prompt.txt
135+
136+ cat >> inline_review_prompt.txt << 'EOF'
137+
138+ Please analyze these changes and provide inline review comments in the following JSON format:
139+
140+ {
141+ "review_summary": "Overall assessment of the PR",
142+ "comments": [
143+ {
144+ "path": "path/to/file.js",
145+ "position": 4,
146+ "body": "Brief, specific comment about this line or section"
147+ }
148+ ]
149+ }
150+
151+ Focus on:
152+ 1. **Critical Issues**: Security vulnerabilities, bugs that will break functionality
153+ 2. **High Priority**: Performance problems, incorrect logic, missing error handling
154+ 3. **Medium Priority**: Code style violations, potential edge cases, unclear code
155+ 4. **Low Priority**: Suggestions for improvement, refactoring opportunities
156+
157+ Guidelines for comments:
158+ - Be specific and actionable
159+ - Use the [POS:N] number shown in the diff as the position value
160+ - Keep comments concise but informative
161+ - Suggest concrete improvements when pointing out issues
162+ - Only comment on actual problems or important improvements
163+
164+ Important:
165+ - Output ONLY valid JSON, no markdown code blocks or backticks
166+ - Start your response with { and end with }
167+ - Use the exact number from [POS:N] markers as the position
168+ - Only comment on changed lines (lines with + or - prefix)
169+ - Comment on the most important issues first
170+ - Limit to maximum 20 most relevant comments
171+ EOF
172+
173+ - name: Run Continue CLI Inline Review
174+ if: env.SKIP_REVIEW != 'true'
175+ shell: bash
176+ env:
177+ CONTINUE_API_KEY: ${{ inputs.continue-api-key }}
178+ run: |
179+ echo "Running Continue CLI for inline review..."
180+
181+ # Validate required inputs
182+ if [ -z "${{ inputs.continue-org }}" ]; then
183+ echo "Error: continue-org input is required"
184+ exit 1
185+ fi
186+
187+ if [ -z "${{ inputs.continue-config }}" ]; then
188+ echo "Error: continue-config input is required"
189+ exit 1
190+ fi
191+
192+ # Log the prompt for debugging
193+ echo "===== START REVIEW PROMPT ====="
194+ head -n 50 inline_review_prompt.txt
195+ echo "... [diff content] ..."
196+ tail -n 20 inline_review_prompt.txt
197+ echo "===== END REVIEW PROMPT ====="
198+
199+ # Run the CLI and capture JSON output
200+ cn --readonly --format json --org "${{ inputs.continue-org }}" --config "${{ inputs.continue-config }}" -p "$(cat inline_review_prompt.txt)" > inline_review_raw.json
201+
202+ # Log the output for debugging
203+ echo "Initial Continue CLI output:"
204+ cat inline_review_raw.json
205+
206+ # Validate JSON output and use it directly
207+ if ! jq empty inline_review_raw.json 2>/dev/null; then
208+ echo "Error: Invalid JSON output from Continue CLI"
209+ exit 1
210+ fi
211+
212+ # Use the JSON output directly
213+ cp inline_review_raw.json inline_review.json
214+ echo "Review output:"
215+ cat inline_review.json
216+
217+ - name: Post Inline Review Comments
218+ if: env.SKIP_REVIEW != 'true'
219+ uses: actions/github-script@v7
220+ with:
221+ script: |
222+ const fs = require('fs');
223+
224+ try {
225+ // Read the review output
226+ let reviewData;
227+ try {
228+ const reviewContent = fs.readFileSync('inline_review.json', 'utf8');
229+ reviewData = JSON.parse(reviewContent);
230+ } catch (parseError) {
231+ console.log('Failed to parse review JSON:', parseError);
232+ reviewData = {
233+ review_summary: 'AI review completed but failed to parse output',
234+ comments: []
235+ };
236+ }
237+
238+ // Get PR number
239+ let prNumber;
240+ if (context.eventName === 'pull_request') {
241+ prNumber = context.payload.pull_request.number;
242+ } else {
243+ prNumber = context.payload.issue.number;
244+ }
245+
246+ // Get the latest commit SHA
247+ const { data: pr } = await github.rest.pulls.get({
248+ owner: context.repo.owner,
249+ repo: context.repo.repo,
250+ pull_number: prNumber
251+ });
252+
253+ const commitSha = pr.head.sha;
254+
255+ // Prepare review comments - filter out comments without required fields
256+ const allComments = reviewData.comments || [];
257+ const validComments = allComments.filter(comment =>
258+ comment.position &&
259+ comment.path &&
260+ comment.body &&
261+ typeof comment.position === 'number' &&
262+ comment.position > 0
263+ );
264+
265+ if (validComments.length < allComments.length) {
266+ console.log(`Filtered out ${allComments.length - validComments.length} comments due to missing/invalid position, path, or body`);
267+ const invalidComments = allComments.filter(c => !validComments.includes(c));
268+ console.log('Invalid comments:', JSON.stringify(invalidComments, null, 2));
269+ }
270+
271+ const comments = validComments.map(comment => ({
272+ path: comment.path,
273+ position: comment.position,
274+ body: comment.body
275+ }));
276+
277+ // Debug: Log the positions we're trying to use
278+ console.log('Attempting to post comments with positions:');
279+ comments.forEach(c => {
280+ console.log(` ${c.path}: position ${c.position}`);
281+ });
282+
283+ // Create the review
284+ if (comments.length > 0) {
285+ try {
286+ await github.rest.pulls.createReview({
287+ owner: context.repo.owner,
288+ repo: context.repo.repo,
289+ pull_number: prNumber,
290+ commit_id: commitSha,
291+ body: `${reviewData.review_summary || 'AI Code Review'}\n\n---\n*💡 To request a new detailed review, comment \`@continue-detailed-review\`*`,
292+ event: 'COMMENT',
293+ comments: comments
294+ });
295+ console.log(`Successfully created review with ${comments.length} inline comments`);
296+ } catch (reviewError) {
297+ console.log('Failed to create review:', reviewError.message);
298+
299+ // Fallback: post as a regular comment if review creation fails
300+ const fallbackBody = `## AI Code Review\n\n${reviewData.review_summary}\n\n` +
301+ `*Failed to post ${comments.length} inline comments. Please review the changes manually.*\n\n` +
302+ `---\n*💡 To request a new detailed review, comment \`@continue-detailed-review\`*`;
303+
304+ await github.rest.issues.createComment({
305+ issue_number: prNumber,
306+ owner: context.repo.owner,
307+ repo: context.repo.repo,
308+ body: fallbackBody
309+ });
310+ }
311+ } else {
312+ // No inline comments, just post the summary
313+ await github.rest.issues.createComment({
314+ issue_number: prNumber,
315+ owner: context.repo.owner,
316+ repo: context.repo.repo,
317+ body: `## AI Code Review\n\n${reviewData.review_summary}\n\n*No specific line comments generated.*\n\n` +
318+ `---\n*💡 To request a new detailed review, comment \`@continue-detailed-review\`*`
319+ });
320+ }
321+
322+ // Add triggered by note if from comment
323+ if (context.eventName === 'issue_comment') {
324+ await github.rest.issues.createComment({
325+ issue_number: prNumber,
326+ owner: context.repo.owner,
327+ repo: context.repo.repo,
328+ body: `*Inline review triggered by @${context.payload.comment.user.login}*`
329+ });
330+ }
331+
332+ } catch (error) {
333+ console.log('Failed to post review:', error.message);
334+ console.log('Error details:', error);
335+ }
336+ env:
337+ GITHUB_TOKEN: ${{ github.token }}
338+
339+ - name: Upload Review Artifacts
340+ if: env.SKIP_REVIEW != 'true' && always()
341+ uses: actions/upload-artifact@v4
342+ with:
343+ name: inline-review-results
344+ path: |
345+ inline_review_raw.json
346+ inline_review.json
347+ inline_review_prompt.txt
348+ pr_diff.txt
349+ pr_diff_annotated.txt
350+ retention-days: 7
No newline at the end of the file
added actions/detailed-review/annotate-diff.js +96 −0
@@ -0,0 +1,96 @@
1+#!/usr/bin/env node
2+
3+/**
4+ * Annotates a git diff with GitHub API positions
5+ *
6+ * Takes a raw diff and adds [POS:N] markers with the correct
7+ * GitHub API positions (cumulative, with +1 between hunks)
8+ */
9+
10+const fs = require("fs");
11+
12+function annotateDiff(diffContent) {
13+ const lines = diffContent.split("\n");
14+ const output = [];
15+ let githubPos = 0;
16+ let inHunk = false;
17+
18+ for (const line of lines) {
19+ // Handle new file - reset position counter
20+ if (line.startsWith("diff --git")) {
21+ githubPos = 0;
22+ inHunk = false;
23+ output.push(line);
24+ continue;
25+ }
26+
27+ // Pass through other git headers unchanged
28+ if (
29+ line.startsWith("index ") ||
30+ line.startsWith("---") ||
31+ line.startsWith("+++") ||
32+ line.startsWith("rename ") ||
33+ line.startsWith("similarity ") ||
34+ line.startsWith("new file") ||
35+ line.startsWith("deleted file") ||
36+ line.startsWith("old mode") ||
37+ line.startsWith("new mode") ||
38+ line.startsWith("Binary files")
39+ ) {
40+ output.push(line);
41+ continue;
42+ }
43+
44+ // Handle hunk headers
45+ if (line.startsWith("@@")) {
46+ if (inHunk) {
47+ githubPos++; // GitHub's +1 between hunks
48+ }
49+ inHunk = true;
50+ output.push(line);
51+ continue;
52+ }
53+
54+ // Handle "no newline" marker - it counts as a position but isn't annotated
55+ if (line.startsWith("\\ No newline")) {
56+ if (inHunk) {
57+ githubPos++; // GitHub counts this as a position
58+ }
59+ output.push(line); // Don't annotate it
60+ continue;
61+ }
62+
63+ // Annotate actual diff lines with GitHub positions
64+ if (inHunk) {
65+ githubPos++;
66+ output.push(`[POS:${githubPos}] ${line}`);
67+ } else {
68+ output.push(line);
69+ }
70+ }
71+
72+ return output.join("\n");
73+}
74+
75+// Main
76+function main() {
77+ // Read diff from stdin or file
78+ let input = "";
79+
80+ if (process.argv.length > 2) {
81+ // Read from file
82+ input = fs.readFileSync(process.argv[2], "utf8");
83+ } else {
84+ // Read from stdin
85+ input = fs.readFileSync(0, "utf8");
86+ }
87+
88+ const annotated = annotateDiff(input);
89+ console.log(annotated);
90+}
91+
92+if (require.main === module) {
93+ main();
94+}
95+
96+module.exports = { annotateDiff };
added actions/detailed-review/annotate-diff.test.js +363 −0
@@ -0,0 +1,363 @@
1+const { annotateDiff } = require("./annotate-diff.js");
2+
3+describe("annotateDiff", () => {
4+ test("single file, single hunk", () => {
5+ const diff = `diff --git a/file.js b/file.js
6+index abc123..def456 100644
7+--- a/file.js
8++++ b/file.js
9+@@ -1,3 +1,4 @@
10+ line1
11+ line2
12++added line
13+ line3`;
14+
15+ const result = annotateDiff(diff);
16+ expect(result).toContain("[POS:1] line1");
17+ expect(result).toContain("[POS:2] line2");
18+ expect(result).toContain("[POS:3] +added line");
19+ expect(result).toContain("[POS:4] line3");
20+ });
21+
22+ test("single file, multiple hunks with +1 between", () => {
23+ const diff = `diff --git a/file.js b/file.js
24+index abc123..def456 100644
25+--- a/file.js
26++++ b/file.js
27+@@ -1,3 +1,3 @@
28+ line1
29+-old line
30++new line
31+ line3
32+@@ -10,3 +10,3 @@
33+ line10
34+-old line 11
35++new line 11
36+ line12`;
37+
38+ const result = annotateDiff(diff);
39+
40+ // First hunk
41+ expect(result).toContain("[POS:1] line1");
42+ expect(result).toContain("[POS:2] -old line");
43+ expect(result).toContain("[POS:3] +new line");
44+ expect(result).toContain("[POS:4] line3");
45+
46+ // Second hunk (should start at 6, because 4 lines + 1 for between hunks)
47+ expect(result).toContain("[POS:6] line10");
48+ expect(result).toContain("[POS:7] -old line 11");
49+ expect(result).toContain("[POS:8] +new line 11");
50+ expect(result).toContain("[POS:9] line12");
51+ });
52+
53+ test("multiple files reset position counter", () => {
54+ const diff = `diff --git a/file1.js b/file1.js
55+index abc123..def456 100644
56+--- a/file1.js
57++++ b/file1.js
58+@@ -1,2 +1,2 @@
59+ line1
60+-old
61++new
62+diff --git a/file2.js b/file2.js
63+index abc123..def456 100644
64+--- a/file2.js
65++++ b/file2.js
66+@@ -1,2 +1,2 @@
67+ first
68+-old2
69++new2`;
70+
71+ const result = annotateDiff(diff);
72+
73+ // File 1
74+ expect(result).toContain("[POS:1] line1");
75+ expect(result).toContain("[POS:2] -old");
76+ expect(result).toContain("[POS:3] +new");
77+
78+ // File 2 - positions should reset
79+ const file2Section = result.split("diff --git a/file2.js")[1];
80+ expect(file2Section).toContain("[POS:1] first");
81+ expect(file2Section).toContain("[POS:2] -old2");
82+ expect(file2Section).toContain("[POS:3] +new2");
83+ });
84+
85+ test("handles new file", () => {
86+ const diff = `diff --git a/newfile.js b/newfile.js
87+new file mode 100644
88+index 0000000..abc123
89+--- /dev/null
90++++ b/newfile.js
91+@@ -0,0 +1,3 @@
92++line1
93++line2
94++line3`;
95+
96+ const result = annotateDiff(diff);
97+ expect(result).toContain("new file mode 100644");
98+ expect(result).toContain("[POS:1] +line1");
99+ expect(result).toContain("[POS:2] +line2");
100+ expect(result).toContain("[POS:3] +line3");
101+ });
102+
103+ test("handles deleted file", () => {
104+ const diff = `diff --git a/deleted.js b/deleted.js
105+deleted file mode 100644
106+index abc123..0000000
107+--- a/deleted.js
108++++ /dev/null
109+@@ -1,3 +0,0 @@
110+-line1
111+-line2
112+-line3`;
113+
114+ const result = annotateDiff(diff);
115+ expect(result).toContain("deleted file mode 100644");
116+ expect(result).toContain("[POS:1] -line1");
117+ expect(result).toContain("[POS:2] -line2");
118+ expect(result).toContain("[POS:3] -line3");
119+ });
120+
121+ test("handles renamed file with changes", () => {
122+ const diff = `diff --git a/old-name.js b/new-name.js
123+similarity index 95%
124+rename from old-name.js
125+rename to new-name.js
126+index abc123..def456 100644
127+--- a/old-name.js
128++++ b/new-name.js
129+@@ -1,3 +1,3 @@
130+ line1
131+-old line
132++new line
133+ line3`;
134+
135+ const result = annotateDiff(diff);
136+ expect(result).toContain("rename from old-name.js");
137+ expect(result).toContain("rename to new-name.js");
138+ expect(result).toContain("[POS:1] line1");
139+ expect(result).toContain("[POS:2] -old line");
140+ expect(result).toContain("[POS:3] +new line");
141+ });
142+
143+ test("handles no newline at end of file", () => {
144+ const diff = `diff --git a/file.js b/file.js
145+index abc123..def456 100644
146+--- a/file.js
147++++ b/file.js
148+@@ -1,2 +1,2 @@
149+ line1
150+-old line
151+\\ No newline at end of file
152++new line
153+\\ No newline at end of file`;
154+
155+ const result = annotateDiff(diff);
156+ expect(result).toContain("[POS:1] line1");
157+ expect(result).toContain("[POS:2] -old line");
158+ // Position 3 is the first "No newline" marker (not annotated but counted)
159+ expect(result).toContain("\\ No newline at end of file");
160+ expect(result).toContain("[POS:4] +new line"); // Position 4 due to "No newline" at position 3
161+ // Position 5 is the second "No newline" marker (not annotated but counted)
162+ expect(result).toContain("\\ No newline at end of file");
163+ // No newline markers should not get [POS:N] annotations
164+ expect(result).not.toContain("[POS:3] \\");
165+ expect(result).not.toContain("[POS:5] \\");
166+ });
167+
168+ test("handles file mode changes", () => {
169+ const diff = `diff --git a/script.sh b/script.sh
170+old mode 100644
171+new mode 100755
172+index abc123..def456 100644
173+--- a/script.sh
174++++ b/script.sh
175+@@ -1,2 +1,2 @@
176+ #!/bin/bash
177+-echo "old"
178++echo "new"`;
179+
180+ const result = annotateDiff(diff);
181+ expect(result).toContain("old mode 100644");
182+ expect(result).toContain("new mode 100755");
183+ expect(result).toContain("[POS:1] #!/bin/bash");
184+ expect(result).toContain('[POS:2] -echo "old"');
185+ expect(result).toContain('[POS:3] +echo "new"');
186+ });
187+
188+ test("empty diff returns empty", () => {
189+ const diff = "";
190+ const result = annotateDiff(diff);
191+ expect(result).toBe("");
192+ });
193+
194+ test("handles binary files - modified", () => {
195+ const diff = `diff --git a/image.png b/image.png
196+index abc123..def456 100644
197+Binary files a/image.png and b/image.png differ`;
198+
199+ const result = annotateDiff(diff);
200+ expect(result).toContain("diff --git a/image.png b/image.png");
201+ expect(result).toContain("Binary files a/image.png and b/image.png differ");
202+ // Binary files line should not be annotated
203+ expect(result).not.toContain("[POS:");
204+ });
205+
206+ test("handles binary files - added", () => {
207+ const diff = `diff --git a/newimage.png b/newimage.png
208+new file mode 100644
209+index 0000000..abc123
210+Binary files /dev/null and b/newimage.png differ`;
211+
212+ const result = annotateDiff(diff);
213+ expect(result).toContain("diff --git a/newimage.png b/newimage.png");
214+ expect(result).toContain("new file mode 100644");
215+ expect(result).toContain(
216+ "Binary files /dev/null and b/newimage.png differ",
217+ );
218+ // Binary files line should not be annotated
219+ expect(result).not.toContain("[POS:");
220+ });
221+
222+ test("handles binary files - deleted", () => {
223+ const diff = `diff --git a/oldimage.png b/oldimage.png
224+deleted file mode 100644
225+index abc123..0000000
226+Binary files a/oldimage.png and /dev/null differ`;
227+
228+ const result = annotateDiff(diff);
229+ expect(result).toContain("diff --git a/oldimage.png b/oldimage.png");
230+ expect(result).toContain("deleted file mode 100644");
231+ expect(result).toContain(
232+ "Binary files a/oldimage.png and /dev/null differ",
233+ );
234+ // Binary files line should not be annotated
235+ expect(result).not.toContain("[POS:");
236+ });
237+
238+ test("handles mixed text and binary files", () => {
239+ const diff = `diff --git a/text.js b/text.js
240+index abc123..def456 100644
241+--- a/text.js
242++++ b/text.js
243+@@ -1,2 +1,2 @@
244+ line1
245+-old
246++new
247+diff --git a/image.png b/image.png
248+index 111111..222222 100644
249+Binary files a/image.png and b/image.png differ
250+diff --git a/another.js b/another.js
251+index 333333..444444 100644
252+--- a/another.js
253++++ b/another.js
254+@@ -1,1 +1,1 @@
255+-foo
256++bar`;
257+
258+ const result = annotateDiff(diff);
259+
260+ // First file (text)
261+ expect(result).toContain("[POS:1] line1");
262+ expect(result).toContain("[POS:2] -old");
263+ expect(result).toContain("[POS:3] +new");
264+
265+ // Second file (binary) - no positions
266+ expect(result).toContain("Binary files a/image.png and b/image.png differ");
267+
268+ // Third file (text) - positions reset
269+ const lastFileSection = result.split("diff --git a/another.js")[1];
270+ expect(lastFileSection).toContain("[POS:1] -foo");
271+ expect(lastFileSection).toContain("[POS:2] +bar");
272+ });
273+
274+ test("multiple no newline markers accumulate positions", () => {
275+ const diff = `diff --git a/file.js b/file.js
276+index abc123..def456 100644
277+--- a/file.js
278++++ b/file.js
279+@@ -1,3 +1,3 @@
280+ line1
281+-old1
282+\\ No newline at end of file
283++new1
284+\\ No newline at end of file
285+@@ -10,3 +10,3 @@
286+ line10
287+-old2
288+\\ No newline at end of file
289++new2
290+\\ No newline at end of file`;
291+
292+ const result = annotateDiff(diff);
293+
294+ // First hunk
295+ expect(result).toContain("[POS:1] line1");
296+ expect(result).toContain("[POS:2] -old1");
297+ // Position 3 is the first "No newline" marker
298+ expect(result).toContain("[POS:4] +new1");
299+ // Position 5 is the second "No newline" marker
300+
301+ // Second hunk (starts at position 7 = 5 + 1 for between hunks + 1)
302+ expect(result).toContain("[POS:7] line10");
303+ expect(result).toContain("[POS:8] -old2");
304+ // Position 9 is the third "No newline" marker
305+ expect(result).toContain("[POS:10] +new2");
306+ // Position 11 is the fourth "No newline" marker
307+
308+ // Verify "No newline" markers are not annotated
309+ expect(result).not.toContain("[POS:3] \\");
310+ expect(result).not.toContain("[POS:5] \\");
311+ expect(result).not.toContain("[POS:9] \\");
312+ expect(result).not.toContain("[POS:11] \\");
313+ });
314+
315+ test("complex multi-file, multi-hunk diff", () => {
316+ const diff = `diff --git a/src/app.js b/src/app.js
317+index abc123..def456 100644
318+--- a/src/app.js
319++++ b/src/app.js
320+@@ -10,4 +10,5 @@ function example() {
321+ console.log("start");
322+ const x = 1;
323+- const y = 2;
324++ const y = 3;
325++ const z = 4;
326+ return x + y;
327+@@ -20,3 +21,4 @@ function another() {
328+ let a = 1;
329+ let b = 2;
330++ let c = 3;
331+ return a + b;
332+diff --git a/src/util.js b/src/util.js
333+index 111111..222222 100644
334+--- a/src/util.js
335++++ b/src/util.js
336+@@ -1,2 +1,3 @@
337++import fs from 'fs';
338+ export function util() {
339+ return true;`;
340+
341+ const result = annotateDiff(diff);
342+
343+ // src/app.js - first hunk
344+ expect(result).toContain('[POS:1] console.log("start");');
345+ expect(result).toContain("[POS:2] const x = 1;");
346+ expect(result).toContain("[POS:3] - const y = 2;");
347+ expect(result).toContain("[POS:4] + const y = 3;");
348+ expect(result).toContain("[POS:5] + const z = 4;");
349+ expect(result).toContain("[POS:6] return x + y;");
350+
351+ // src/app.js - second hunk (7 = 6 + 1 for between hunks)
352+ expect(result).toContain("[POS:8] let a = 1;");
353+ expect(result).toContain("[POS:9] let b = 2;");
354+ expect(result).toContain("[POS:10] + let c = 3;");
355+ expect(result).toContain("[POS:11] return a + b;");
356+
357+ // src/util.js - new file, positions reset
358+ const utilSection = result.split("diff --git a/src/util.js")[1];
359+ expect(utilSection).toContain("[POS:1] +import fs from 'fs';");
360+ expect(utilSection).toContain("[POS:2] export function util() {");
361+ expect(utilSection).toContain("[POS:3] return true;");
362+ });
363+});
added actions/detailed-review/package.json +19 −0
@@ -0,0 +1,19 @@
1+{
2+ "name": "@continue/pr-review-scripts",
3+ "version": "1.0.0",
4+ "private": true,
5+ "description": "Scripts for Continue PR Review Action",
6+ "scripts": {
7+ "test": "jest",
8+ "test:watch": "jest --watch"
9+ },
10+ "devDependencies": {
11+ "jest": "^29.7.0"
12+ },
13+ "jest": {
14+ "testEnvironment": "node",
15+ "testMatch": [
16+ "**/*.test.js"
17+ ]
18+ }
19+}
added actions/general-review/action.yml +228 −0
@@ -0,0 +1,228 @@
1+name: 'Continue PR Review'
2+description: 'Automated code review for pull requests using Continue CLI'
3+author: 'Continue Dev, Inc.'
4+
5+inputs:
6+ continue-api-key:
7+ description: 'API key for Continue service'
8+ required: true
9+ continue-org:
10+ description: 'Organization for Continue config'
11+ required: true
12+ continue-config:
13+ description: 'Config path to use (e.g., "myorg/review-bot")'
14+ required: true
15+
16+runs:
17+ using: 'composite'
18+ steps:
19+ - name: Checkout Repository
20+ uses: actions/checkout@v4
21+
22+ - name: Check Authorization
23+ shell: bash
24+ env:
25+ # Only move the dangerous check to env to prevent shell injection
26+ HAS_TRIGGER_PHRASE: ${{ contains(github.event.comment.body, '@continue-general-review') }}
27+ run: |
28+ # Check if this action should run based on event type and user permissions
29+ SHOULD_RUN="false"
30+
31+ if [ "${{ github.event_name }}" = "pull_request" ]; then
32+ # Check PR author association
33+ AUTHOR_ASSOC="${{ github.event.pull_request.author_association }}"
34+ if [ "$AUTHOR_ASSOC" = "OWNER" ] || [ "$AUTHOR_ASSOC" = "MEMBER" ] || [ "$AUTHOR_ASSOC" = "COLLABORATOR" ]; then
35+ SHOULD_RUN="true"
36+ else
37+ echo "::notice::Skipping review - PR author is not a team member (association: $AUTHOR_ASSOC)"
38+ fi
39+ elif [ "${{ github.event_name }}" = "issue_comment" ]; then
40+ # Check if it's a PR comment with the trigger phrase
41+ if [ "${{ github.event.issue.pull_request }}" != "" ] && [ "$HAS_TRIGGER_PHRASE" = "true" ]; then
42+ COMMENTER_ASSOC="${{ github.event.comment.author_association }}"
43+ if [ "$COMMENTER_ASSOC" = "OWNER" ] || [ "$COMMENTER_ASSOC" = "MEMBER" ] || [ "$COMMENTER_ASSOC" = "COLLABORATOR" ]; then
44+ SHOULD_RUN="true"
45+ else
46+ echo "::notice::Skipping review - Commenter is not a team member (association: $COMMENTER_ASSOC)"
47+ fi
48+ else
49+ echo "::notice::Skipping review - Comment does not contain @continue-general-review trigger, or is not on a PR"
50+ fi
51+ else
52+ echo "::notice::Skipping review - Unsupported event type: ${{ github.event_name }}"
53+ fi
54+
55+ echo "SHOULD_RUN=$SHOULD_RUN" >> $GITHUB_ENV
56+
57+ - name: Setup Node.js
58+ if: env.SHOULD_RUN == 'true'
59+ uses: actions/setup-node@v4
60+ with:
61+ node-version: 20
62+
63+ - name: Install Continue CLI
64+ if: env.SHOULD_RUN == 'true'
65+ shell: bash
66+ run: npm install -g @continuedev/cli@1.4.25
67+
68+ - name: Build PR Review Prompt
69+ if: env.SHOULD_RUN == 'true'
70+ shell: bash
71+ env:
72+ GH_TOKEN: ${{ github.token }}
73+ run: |
74+ # Get PR number based on event type
75+ if [ "${{ github.event_name }}" = "pull_request" ]; then
76+ PR_NUMBER="${{ github.event.number }}"
77+ else
78+ # For issue_comment event on a PR
79+ PR_NUMBER="${{ github.event.issue.number }}"
80+ fi
81+
82+ # Get PR diff
83+ gh pr diff $PR_NUMBER > pr_diff.txt
84+
85+ # Create review prompt
86+ cat > review_prompt.txt << 'EOF'
87+ You are conducting a code review for a pull request. Below is the git diff showing all the changes:
88+
89+ EOF
90+
91+ echo "--- PR DIFF START ---" >> review_prompt.txt
92+ cat pr_diff.txt >> review_prompt.txt
93+ echo "--- PR DIFF END ---" >> review_prompt.txt
94+
95+ cat >> review_prompt.txt << 'EOF'
96+
97+ Please analyze these changes and provide a comprehensive code review. Consider:
98+
99+ 1. **Code Quality**: Are there any bugs, performance issues, or code smells?
100+ 2. **Best Practices**: Does the code follow established patterns and conventions?
101+ 3. **Security**: Are there any potential security vulnerabilities?
102+ 4. **Testing**: Are appropriate tests included or updated?
103+ 5. **Documentation**: Is documentation adequate for the changes?
104+ 6. **Architecture**: Do the changes fit well with the existing codebase structure?
105+
106+ You can use the available tools to explore the codebase and understand context better.
107+
108+ Format your response as a markdown code review with the following structure:
109+
110+ ## Code Review Summary
111+
112+ ### ✅ Strengths
113+ - **[Aspect]**: [Description of what was done well]
114+
115+ ### ⚠️ Issues Found
116+
117+ Only include the severity subheaders below if you actually found issues at that level:
118+
119+ #### Critical
120+ - **[Issue Title]**: [Description of critical issues that must be fixed before merging]
121+
122+ #### High
123+ - **[Issue Title]**: [Description of high-priority issues that should be fixed]
124+
125+ #### Medium
126+ - **[Issue Title]**: [Description of issues that should be addressed]
127+
128+ #### Low
129+ - **[Issue Title]**: [Description of minor issues or nice-to-have improvements]
130+
131+
132+ ### 💡 Suggestions
133+ - **[Suggestion Title]**: [Description of improvement recommendations]
134+
135+ ### 🚀 Overall Assessment
136+ [Provide overall recommendation: APPROVE, REQUEST_CHANGES, or COMMENT]
137+
138+ Only call the 'exit' tool if you find critical security vulnerabilities or bugs that would break production.
139+ EOF
140+
141+ - name: Run Continue CLI Review
142+ if: env.SHOULD_RUN == 'true'
143+ shell: bash
144+ env:
145+ CONTINUE_API_KEY: ${{ inputs.continue-api-key }}
146+ CONTINUE_ORG: ${{ inputs.continue-org }}
147+ CONTINUE_CONFIG: ${{ inputs.continue-config }}
148+ run: |
149+ echo "Running Continue CLI with prompt:"
150+ echo "=================================="
151+ cat review_prompt.txt
152+ echo "=================================="
153+ echo ""
154+
155+ # Validate inputs to prevent command injection
156+ if [[ ! "$CONTINUE_ORG" =~ ^[a-zA-Z0-9_-]+$ ]]; then
157+ echo "Error: Invalid organization name. Must contain only alphanumeric characters, hyphens, and underscores."
158+ exit 1
159+ fi
160+
161+ if [[ ! "$CONTINUE_CONFIG" =~ ^[a-zA-Z0-9_/-]+$ ]]; then
162+ echo "Error: Invalid config path. Must contain only alphanumeric characters, hyphens, underscores, and forward slashes."
163+ exit 1
164+ fi
165+
166+ # Run the CLI with validated config
167+ cn --readonly --org "$CONTINUE_ORG" --config "$CONTINUE_CONFIG" -p "$(cat review_prompt.txt)" > code_review.md
168+
169+ - name: Upload Review Results
170+ if: env.SHOULD_RUN == 'true' && always()
171+ uses: actions/upload-artifact@v4
172+ with:
173+ name: code-review-results
174+ path: |
175+ code_review.md
176+ review_prompt.txt
177+ pr_diff.txt
178+ retention-days: 30
179+
180+ - name: Comment PR with Review
181+ if: env.SHOULD_RUN == 'true' && always()
182+ uses: actions/github-script@v7
183+ with:
184+ script: |
185+ const fs = require('fs');
186+
187+ try {
188+ let reviewContent = '';
189+
190+ if (fs.existsSync('code_review.md') && fs.statSync('code_review.md').size > 0) {
191+ reviewContent = fs.readFileSync('code_review.md', 'utf8');
192+ } else {
193+ reviewContent = '⚠️ AI review completed but no review output was generated. Check the action logs for details.';
194+ }
195+
196+ // Get PR number based on event type
197+ let prNumber;
198+ if (context.eventName === 'pull_request') {
199+ prNumber = context.payload.pull_request.number;
200+ } else {
201+ // For issue_comment event
202+ prNumber = context.payload.issue.number;
203+ }
204+
205+ // Add a header if triggered by comment
206+ if (context.eventName === 'issue_comment') {
207+ reviewContent = `*Triggered by @${context.payload.comment.user.login}'s request*\n\n${reviewContent}`;
208+ }
209+
210+ // Add instructions for re-review
211+ reviewContent += '\n\n---\n*💡 To request a new review, comment `@continue-general-review`*';
212+
213+ // Create new comment
214+ await github.rest.issues.createComment({
215+ issue_number: prNumber,
216+ owner: context.repo.owner,
217+ repo: context.repo.repo,
218+ body: reviewContent
219+ });
220+ console.log(`Successfully created new comment on PR #${prNumber}`);
221+ } catch (error) {
222+ console.log('Failed to post comment:', error.message);
223+ console.log('Error details:', error);
224+ }
225+
226+branding:
227+ icon: 'code'
228+ color: 'blue'
No newline at the end of the file