From b64b7e8c024e44b20f63f3faf14af52264cccfb6 Mon Sep 17 00:00:00 2001 From: Brian Douglas Date: Fri, 26 Sep 2025 09:42:53 -0700 Subject: [PATCH] fix: Simplify review bot, remove detailed review, keep general review only (#7976) --- .github/pull_request_template.md | 2 +- .../workflows/continue-detailed-review.yaml | 25 - .github/workflows/pr-checks.yaml | 26 -- actions/README.md | 129 +----- actions/detailed-review/action.yml | 434 ------------------ actions/detailed-review/annotate-diff.js | 96 ---- actions/detailed-review/annotate-diff.test.js | 363 --------------- actions/detailed-review/package.json | 19 - actions/general-review/action.yml | 393 ++++++++++++---- 9 files changed, 328 insertions(+), 1159 deletions(-) delete mode 100644 .github/workflows/continue-detailed-review.yaml delete mode 100644 actions/detailed-review/action.yml delete mode 100644 actions/detailed-review/annotate-diff.js delete mode 100644 actions/detailed-review/annotate-diff.test.js delete mode 100644 actions/detailed-review/package.json diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md index d8b354440..281f61c1f 100644 --- a/.github/pull_request_template.md +++ b/.github/pull_request_template.md @@ -5,7 +5,7 @@ ## AI Code Review - **Team members only**: AI review runs automatically when PR is opened or marked ready for review -- Team members can also trigger a review by commenting `@continue-general-review` or `@continue-detailed-review` +- Team members can also trigger a review by commenting `@continue-review` ## Checklist diff --git a/.github/workflows/continue-detailed-review.yaml b/.github/workflows/continue-detailed-review.yaml deleted file mode 100644 index 103b9c7df..000000000 --- a/.github/workflows/continue-detailed-review.yaml +++ /dev/null @@ -1,25 +0,0 @@ -name: Continue Detailed Review - -on: - pull_request: - types: [opened, ready_for_review] - issue_comment: - types: [created] - -permissions: - contents: read - pull-requests: write - issues: write - -jobs: - detailed-code-review: - name: Continue Detailed Review - runs-on: ubuntu-latest - timeout-minutes: 10 - steps: - - name: Run Detailed PR Review - uses: continuedev/continue/actions/detailed-review@main - with: - continue-api-key: ${{ secrets.CONTINUE_API_KEY }} - continue-org: continuedev - continue-config: continuedev/review-bot diff --git a/.github/workflows/pr-checks.yaml b/.github/workflows/pr-checks.yaml index 370acb854..0155bbfb4 100644 --- a/.github/workflows/pr-checks.yaml +++ b/.github/workflows/pr-checks.yaml @@ -343,31 +343,6 @@ jobs: # GitHub does not have a way of requiring that all checks pass (you must manually select each job) # This action at least lets us manage the list of required tests via source control - pr-review-action-tests: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v5 - - uses: actions/setup-node@v5 - with: - node-version: 20 - - - name: Cache PR review action node modules - uses: actions/cache@v4 - id: pr-review-cache - with: - path: actions/detailed-review/node_modules - key: ${{ runner.os }}-pr-review-action-${{ hashFiles('actions/detailed-review/package.json') }} - - - name: Install dependencies - if: steps.pr-review-cache.outputs.cache-hit != 'true' - run: | - cd actions/detailed-review - npm install - - - name: Run tests - run: | - cd actions/detailed-review - npm test # so that creators of new jobs can add them to this list require-all-checks-to-pass: @@ -385,7 +360,6 @@ jobs: - vscode-package-extension-linux - vscode-e2e-tests - jetbrains-tests - - pr-review-action-tests steps: - name: Decide whether the needed jobs succeeded or failed diff --git a/actions/README.md b/actions/README.md index 6d3bbf377..2e0967d7e 100644 --- a/actions/README.md +++ b/actions/README.md @@ -4,64 +4,19 @@ GitHub Actions that provide automated code reviews for pull requests using Conti ## Available Actions -This repository provides two GitHub Actions for different review styles: +This repository provides a GitHub Action for automated PR reviews: -### 1. General Review Action +### General Review Action Provides high-level PR assessment with overall feedback and recommendations. -- **Path:** `continuedev/continue/actions/general-review@` -- **Trigger:** `@continue-general-review` +- **Path:** `continuedev/continue/actions/general-review@main` +- **Trigger:** `@continue-review` - **Output:** Summary comment with strengths, issues, and recommendations -### 2. Detailed Review Action - -Provides line-by-line inline comments on specific code changes. - -- **Path:** `continuedev/continue/actions/detailed-review@` -- **Trigger:** `@continue-detailed-review` -- **Output:** Inline review comments on specific lines of code - ## Quick Start -### Using Both Actions Together - -```yaml -name: PR Reviews -on: - pull_request: - types: [opened, ready_for_review] - issue_comment: - types: [created] - -permissions: - contents: read - pull-requests: write - issues: write - -jobs: - general-review: - runs-on: ubuntu-latest - timeout-minutes: 10 - steps: - - uses: continuedev/continue/actions/general-review@ - with: - continue-api-key: ${{ secrets.CONTINUE_API_KEY }} - continue-org: "your-org-name" - continue-config: "your-org-name/review-bot" - - detailed-review: - runs-on: ubuntu-latest - timeout-minutes: 10 - steps: - - uses: continuedev/continue/actions/detailed-review@ - with: - continue-api-key: ${{ secrets.CONTINUE_API_KEY }} - continue-org: "your-org-name" - continue-config: "your-org-name/review-bot" -``` - -### General Review Only +### Setting up General Review ```yaml name: PR General Review @@ -81,34 +36,7 @@ jobs: runs-on: ubuntu-latest timeout-minutes: 10 steps: - - uses: continuedev/continue/actions/general-review@ - with: - continue-api-key: ${{ secrets.CONTINUE_API_KEY }} - continue-org: "your-org-name" - continue-config: "your-org-name/review-bot" -``` - -### Detailed Review Only - -```yaml -name: PR Detailed Review -on: - pull_request: - types: [opened, ready_for_review] - issue_comment: - types: [created] - -permissions: - contents: read - pull-requests: write - issues: write - -jobs: - review: - runs-on: ubuntu-latest - timeout-minutes: 10 - steps: - - uses: continuedev/continue/actions/detailed-review@ + - uses: continuedev/continue/actions/general-review@main with: continue-api-key: ${{ secrets.CONTINUE_API_KEY }} continue-org: "your-org-name" @@ -117,7 +45,7 @@ jobs: ## Inputs -Both actions accept the same inputs: +The action accepts the following inputs: | Input | Description | Required | | ------------------ | -------------------------------------- | -------- | @@ -155,7 +83,7 @@ The workflow requires these permissions: ## Triggering Reviews -Both actions can be triggered in two ways: +The action can be triggered in two ways: ### Automatic Triggers @@ -166,12 +94,9 @@ Both actions can be triggered in two ways: Team members can trigger reviews by commenting on any pull request: -- `@continue-general-review` - Triggers a general review -- `@continue-detailed-review` - Triggers a detailed inline review +- `@continue-review` - Triggers a review -## Review Outputs - -### General Review Output +## Review Output The general review provides a structured comment that includes: @@ -180,46 +105,24 @@ The general review provides a structured comment that includes: - **Suggestions**: Improvement recommendations - **Overall Assessment**: Final recommendation (APPROVE, REQUEST_CHANGES, or COMMENT) -### Detailed Review Output - -The detailed review provides: - -- **Inline Comments**: Specific feedback on individual lines of code -- **Position Markers**: Comments appear directly on the changed lines -- **Review Summary**: Overall assessment of the changes -- **Actionable Feedback**: Specific suggestions for each issue found - ## How It Works -### General Review Process - 1. Checks out repository code 2. Fetches PR diff using GitHub CLI 3. Generates a comprehensive review prompt 4. Runs Continue CLI with specified configuration 5. Posts review as a PR comment -### Detailed Review Process - -1. Checks out repository code -2. Fetches PR diff with GitHub API positions -3. Annotates diff with position markers -4. Generates inline review prompt -5. Runs Continue CLI for detailed analysis -6. Posts inline comments using GitHub's review API - ## Versioning -We recommend using a specific commit SHA for stability and predictability: +We recommend using the main branch: -- `@` - Pins to a specific commit for maximum stability (recommended) -- `@main` - Uses the latest code from the main branch (for bleeding edge) -- `@v1` - Uses a version tag when available +- `@main` - Uses the latest code from the main branch Example: ```yaml -uses: continuedev/continue/actions/general-review@64bda6b2b3dac1037e9895dbee4ce1d35565e1fe +uses: continuedev/continue/actions/general-review@main ``` ## Troubleshooting @@ -236,12 +139,6 @@ uses: continuedev/continue/actions/general-review@64bda6b2b3dac1037e9895dbee4ce1 - Verify your Continue configuration is correct - Ensure your Continue API key is valid -### Inline comments not appearing (Detailed Review) - -- Check that the PR has a valid diff -- Verify GitHub API permissions are correct -- Review action logs for position calculation errors - ## Support For issues or questions: diff --git a/actions/detailed-review/action.yml b/actions/detailed-review/action.yml deleted file mode 100644 index f8273cc50..000000000 --- a/actions/detailed-review/action.yml +++ /dev/null @@ -1,434 +0,0 @@ -name: 'Continue Detailed PR Review' -description: 'Automated inline code review for pull requests using Continue CLI' -author: 'Continue Dev, Inc.' - -inputs: - continue-api-key: - description: 'API key for Continue service' - required: true - continue-org: - description: 'Organization for Continue config' - required: true - continue-config: - description: 'Config path to use (e.g., "myorg/review-bot")' - required: true - -runs: - using: 'composite' - steps: - - name: Checkout Repository - uses: actions/checkout@v4 - - - name: Check Authorization - shell: bash - env: - # Only move the dangerous check to env to prevent shell injection - HAS_TRIGGER_PHRASE: ${{ contains(github.event.comment.body, '@continue-detailed-review') }} - run: | - # Check if this action should run based on event type and user permissions - SHOULD_RUN="false" - - if [ "${{ github.event_name }}" = "pull_request" ]; then - # Check if PR is a draft - if [ "${{ github.event.pull_request.draft }}" = "true" ]; then - echo "::notice::Skipping review - PR is a draft" - else - # Check PR author association - AUTHOR_ASSOC="${{ github.event.pull_request.author_association }}" - if [ "$AUTHOR_ASSOC" = "OWNER" ] || [ "$AUTHOR_ASSOC" = "MEMBER" ] || [ "$AUTHOR_ASSOC" = "COLLABORATOR" ]; then - SHOULD_RUN="true" - else - echo "::notice::Skipping review - PR author is not a team member (association: $AUTHOR_ASSOC)" - fi - fi - elif [ "${{ github.event_name }}" = "issue_comment" ]; then - # Check if it's a PR comment with the trigger phrase - if [ "${{ github.event.issue.pull_request }}" != "" ] && [ "$HAS_TRIGGER_PHRASE" = "true" ]; then - COMMENTER_ASSOC="${{ github.event.comment.author_association }}" - if [ "$COMMENTER_ASSOC" = "OWNER" ] || [ "$COMMENTER_ASSOC" = "MEMBER" ] || [ "$COMMENTER_ASSOC" = "COLLABORATOR" ]; then - SHOULD_RUN="true" - else - echo "::notice::Skipping review - Commenter is not a team member (association: $COMMENTER_ASSOC)" - fi - else - echo "::notice::Skipping review - Comment does not contain @continue-detailed-review trigger, or is not on a PR" - fi - else - echo "::notice::Skipping review - Event type ${{ github.event_name }} is not supported" - fi - - if [ "$SHOULD_RUN" != "true" ]; then - echo "SKIP_REVIEW=true" >> $GITHUB_ENV - exit 0 - fi - - echo "SKIP_REVIEW=false" >> $GITHUB_ENV - - - name: Setup Node.js - if: env.SKIP_REVIEW != 'true' - uses: actions/setup-node@v4 - with: - node-version: 20 - - - name: Install Continue CLI - if: env.SKIP_REVIEW != 'true' - shell: bash - run: npm install -g @continuedev/cli@1.4.30 - - - name: Build Inline Review Prompt - if: env.SKIP_REVIEW != 'true' - shell: bash - env: - GH_TOKEN: ${{ github.token }} - run: | - # Get PR number based on event type - if [ "${{ github.event_name }}" = "pull_request" ]; then - PR_NUMBER="${{ github.event.number }}" - else - # For issue_comment event on a PR - PR_NUMBER="${{ github.event.issue.number }}" - fi - - # Get PR files with line numbers - gh api repos/${{ github.repository }}/pulls/$PR_NUMBER/files > pr_files.json - - # Get PR diff with context - gh pr diff $PR_NUMBER --color=never > pr_diff.txt - - # Annotate diff with GitHub API positions - node ${{ github.action_path }}/annotate-diff.js pr_diff.txt > pr_diff_annotated.txt - - # Debug: Show sample of annotated diff - echo "=== SAMPLE OF ANNOTATED DIFF ===" - head -100 pr_diff_annotated.txt | grep -E "^\[POS:|^@@|^diff --git" || head -50 pr_diff_annotated.txt - echo "=== END SAMPLE ===" - - # Create review prompt for inline comments - cat > inline_review_prompt.txt << 'EOF' - You are conducting a detailed inline code review for a pull request. - - Your task is to analyze the code changes and generate specific, actionable review comments for individual lines or small sections of code. - - IMPORTANT: The diff below has been annotated with [POS:N] markers showing the exact position for each line. - - Example of how to use the position markers: - ``` - diff --git a/src/app.js b/src/app.js - index abc123..def456 100644 - --- a/src/app.js - +++ b/src/app.js - @@ -10,4 +10,6 @@ function example() { - [POS:1] console.log("context"); - [POS:2] - const old = "remove this"; - [POS:3] + const new = "add this"; - [POS:4] + const risky = eval(userInput); <-- To comment here, use position: 4 - [POS:5] return result; - [POS:6] + console.log("done"); - @@ -20,3 +22,4 @@ function another() { - [POS:1] let x = 1; - [POS:2] + let y = 2; <-- To comment here, use position: 2 - ``` - - To comment on a line, simply use the number from its [POS:N] marker as the position value. - For example: {"path": "src/app.js", "position": 4, "body": "Avoid using eval with user input"} - - Below is the annotated PR diff: - - EOF - - cat pr_diff_annotated.txt >> inline_review_prompt.txt - - cat >> inline_review_prompt.txt << 'EOF' - - Please analyze these changes and provide inline review comments in the following JSON format: - - { - "review_summary": "Overall assessment of the PR", - "comments": [ - { - "path": "path/to/file.js", - "position": 4, - "body": "Brief, specific comment about this line or section" - } - ] - } - - Focus on: - 1. **Critical Issues**: Security vulnerabilities, bugs that will break functionality - 2. **High Priority**: Performance problems, incorrect logic, missing error handling - 3. **Medium Priority**: Code style violations, potential edge cases, unclear code - 4. **Low Priority**: Suggestions for improvement, refactoring opportunities - - Guidelines for comments: - - Be specific and actionable - - Use the [POS:N] number shown in the diff as the position value - - Keep comments concise but informative - - Suggest concrete improvements when pointing out issues - - Only comment on actual problems or important improvements - - Important: - - Output ONLY valid JSON, no markdown code blocks or backticks - - Start your response with { and end with } - - Use the exact number from [POS:N] markers as the position - - Only comment on changed lines (lines with + or - prefix) - - Comment on the most important issues first - - Limit to maximum 20 most relevant comments - EOF - - - name: Run Continue CLI Inline Review - if: env.SKIP_REVIEW != 'true' - shell: bash - env: - CONTINUE_API_KEY: ${{ inputs.continue-api-key }} - run: | - echo "Running Continue CLI for inline review..." - - # Validate required inputs - if [ -z "${{ inputs.continue-org }}" ]; then - echo "Error: continue-org input is required" - exit 1 - fi - - if [ -z "${{ inputs.continue-config }}" ]; then - echo "Error: continue-config input is required" - exit 1 - fi - - # Validate API key - if [ -z "$CONTINUE_API_KEY" ]; then - echo "Warning: CONTINUE_API_KEY environment variable is not set" - # Create fallback review and continue - cat > inline_review.json << 'EOF' - { - "review_summary": "AI review skipped: CONTINUE_API_KEY not configured.", - "comments": [] - } - EOF - echo "SKIP_CLI=true" >> $GITHUB_ENV - else - echo "SKIP_CLI=false" >> $GITHUB_ENV - fi - - # Log the prompt for debugging - echo "===== START REVIEW PROMPT =====" - head -n 50 inline_review_prompt.txt - echo "... [diff content] ..." - tail -n 20 inline_review_prompt.txt - echo "===== END REVIEW PROMPT =====" - - # Test Continue CLI availability - if [ "$SKIP_CLI" != "true" ]; then - echo "Testing Continue CLI..." - if ! cn --version; then - echo "Warning: Continue CLI not found or not working" - cat > inline_review.json << 'EOF' - { - "review_summary": "AI review skipped: Continue CLI installation failed.", - "comments": [] - } - EOF - echo "SKIP_CLI=true" >> $GITHUB_ENV - else - echo "Continue CLI version: $(cn --version)" - fi - fi - - # Run the CLI and capture JSON output with error handling - if [ "$SKIP_CLI" != "true" ]; then - echo "Executing Continue CLI with config: ${{ inputs.continue-org }}/${{ inputs.continue-config }}" - - # Write prompt to temp file for better handling - PROMPT_FILE="/tmp/continue-prompt-$.txt" - cp inline_review_prompt.txt "$PROMPT_FILE" - - # Use timeout to prevent hanging (240 seconds = 4 minutes) - if ! timeout 240 cn --config "${{ inputs.continue-org }}/${{ inputs.continue-config }}" -p "@$PROMPT_FILE" --allow Bash --format json > inline_review_raw.json 2>cli_error.log; then - echo "Warning: Continue CLI command failed" - echo "CLI error log:" - cat cli_error.log - - # Create fallback review - cat > inline_review.json << 'EOF' - { - "review_summary": "AI review failed due to service initialization issues. Please check the Continue API key and configuration.", - "comments": [] - } - EOF - echo "Created fallback review due to CLI failure" - else - # Log the output for debugging - echo "Initial Continue CLI output:" - cat inline_review_raw.json - - # Validate JSON output and use it directly - if ! jq empty inline_review_raw.json 2>/dev/null; then - echo "Warning: Invalid JSON output from Continue CLI, using fallback" - cat > inline_review.json << 'EOF' - { - "review_summary": "AI review completed but failed to parse output correctly.", - "comments": [] - } - EOF - else - # Use the JSON output directly - cp inline_review_raw.json inline_review.json - echo "Review output:" - cat inline_review.json - fi - fi - fi - - - name: Post Inline Review Comments - if: env.SKIP_REVIEW != 'true' - uses: actions/github-script@v7 - with: - script: | - const fs = require('fs'); - - try { - // Read the review output - let reviewData; - try { - const reviewContent = fs.readFileSync('inline_review.json', 'utf8'); - reviewData = JSON.parse(reviewContent); - } catch (parseError) { - console.log('Failed to parse review JSON:', parseError); - reviewData = { - review_summary: 'AI review completed but failed to parse output', - comments: [] - }; - } - - // Get PR number - let prNumber; - if (context.eventName === 'pull_request') { - prNumber = context.payload.pull_request.number; - } else { - prNumber = context.payload.issue.number; - } - - // Get the latest commit SHA - const { data: pr } = await github.rest.pulls.get({ - owner: context.repo.owner, - repo: context.repo.repo, - pull_number: prNumber - }); - - const commitSha = pr.head.sha; - - // Prepare review comments - filter out comments without required fields - const allComments = reviewData.comments || []; - const validComments = allComments.filter(comment => - comment.position && - comment.path && - comment.body && - typeof comment.position === 'number' && - comment.position > 0 - ); - - if (validComments.length < allComments.length) { - console.log(`Filtered out ${allComments.length - validComments.length} comments due to missing/invalid position, path, or body`); - const invalidComments = allComments.filter(c => !validComments.includes(c)); - console.log('Invalid comments:', JSON.stringify(invalidComments, null, 2)); - } - - // Deduplicate comments based on path + position + body - const uniqueComments = []; - const seen = new Set(); - - for (const comment of validComments) { - const key = `${comment.path}:${comment.position}:${comment.body}`; - if (!seen.has(key)) { - seen.add(key); - uniqueComments.push(comment); - } - } - - if (uniqueComments.length < validComments.length) { - console.log(`Filtered out ${validComments.length - uniqueComments.length} duplicate comments (same path + position + body)`); - } - - const comments = uniqueComments.map(comment => ({ - path: comment.path, - position: comment.position, - body: comment.body - })); - - // Debug: Log the positions we're trying to use - console.log('Attempting to post comments with positions:'); - comments.forEach(c => { - console.log(` ${c.path}: position ${c.position}`); - }); - - // Create the review - if (comments.length > 0) { - try { - let reviewBody = `${reviewData.review_summary || 'AI Code Review'}\n\n---\n*šŸ’” To request a new detailed review, comment \`@continue-detailed-review\`*`; - - // Add triggered by note if from comment - if (context.eventName === 'issue_comment') { - reviewBody = `*Triggered by @${context.payload.comment.user.login}'s request*\n\n${reviewBody}`; - } - - await github.rest.pulls.createReview({ - owner: context.repo.owner, - repo: context.repo.repo, - pull_number: prNumber, - commit_id: commitSha, - body: reviewBody, - event: 'COMMENT', - comments: comments - }); - console.log(`Successfully created review with ${comments.length} inline comments`); - } catch (reviewError) { - console.log('Failed to create review:', reviewError.message); - - // Fallback: post as a regular comment if review creation fails - const fallbackBody = `## AI Code Review\n\n${reviewData.review_summary}\n\n` + - `*Failed to post ${comments.length} inline comments. Please review the changes manually.*\n\n` + - `---\n*šŸ’” To request a new detailed review, comment \`@continue-detailed-review\`*`; - - await github.rest.issues.createComment({ - issue_number: prNumber, - owner: context.repo.owner, - repo: context.repo.repo, - body: fallbackBody - }); - } - } else { - // No inline comments, just post the summary - let summaryBody = `## AI Code Review\n\n${reviewData.review_summary}\n\n*No specific line comments generated.*\n\n` + - `---\n*šŸ’” To request a new detailed review, comment \`@continue-detailed-review\`*`; - - // Add triggered by note if from comment - if (context.eventName === 'issue_comment') { - summaryBody = `*Triggered by @${context.payload.comment.user.login}'s request*\n\n${summaryBody}`; - } - - await github.rest.issues.createComment({ - issue_number: prNumber, - owner: context.repo.owner, - repo: context.repo.repo, - body: summaryBody - }); - } - - } catch (error) { - console.log('Failed to post review:', error.message); - console.log('Error details:', error); - } - env: - GITHUB_TOKEN: ${{ github.token }} - - - name: Upload Review Artifacts - if: env.SKIP_REVIEW != 'true' && always() - uses: actions/upload-artifact@v4 - with: - name: inline-review-results - path: | - inline_review_raw.json - inline_review.json - inline_review_prompt.txt - pr_diff.txt - pr_diff_annotated.txt - retention-days: 7 \ No newline at end of file diff --git a/actions/detailed-review/annotate-diff.js b/actions/detailed-review/annotate-diff.js deleted file mode 100644 index b4bdb803e..000000000 --- a/actions/detailed-review/annotate-diff.js +++ /dev/null @@ -1,96 +0,0 @@ -#!/usr/bin/env node - -/** - * Annotates a git diff with GitHub API positions - * - * Takes a raw diff and adds [POS:N] markers with the correct - * GitHub API positions (cumulative, with +1 between hunks) - */ - -const fs = require("fs"); - -function annotateDiff(diffContent) { - const lines = diffContent.split("\n"); - const output = []; - let githubPos = 0; - let inHunk = false; - - for (const line of lines) { - // Handle new file - reset position counter - if (line.startsWith("diff --git")) { - githubPos = 0; - inHunk = false; - output.push(line); - continue; - } - - // Pass through other git headers unchanged - if ( - line.startsWith("index ") || - line.startsWith("---") || - line.startsWith("+++") || - line.startsWith("rename ") || - line.startsWith("similarity ") || - line.startsWith("new file") || - line.startsWith("deleted file") || - line.startsWith("old mode") || - line.startsWith("new mode") || - line.startsWith("Binary files") - ) { - output.push(line); - continue; - } - - // Handle hunk headers - if (line.startsWith("@@")) { - if (inHunk) { - githubPos++; // GitHub's +1 between hunks - } - inHunk = true; - output.push(line); - continue; - } - - // Handle "no newline" marker - it counts as a position but isn't annotated - if (line.startsWith("\\ No newline")) { - if (inHunk) { - githubPos++; // GitHub counts this as a position - } - output.push(line); // Don't annotate it - continue; - } - - // Annotate actual diff lines with GitHub positions - if (inHunk) { - githubPos++; - output.push(`[POS:${githubPos}] ${line}`); - } else { - output.push(line); - } - } - - return output.join("\n"); -} - -// Main -function main() { - // Read diff from stdin or file - let input = ""; - - if (process.argv.length > 2) { - // Read from file - input = fs.readFileSync(process.argv[2], "utf8"); - } else { - // Read from stdin - input = fs.readFileSync(0, "utf8"); - } - - const annotated = annotateDiff(input); - console.log(annotated); -} - -if (require.main === module) { - main(); -} - -module.exports = { annotateDiff }; diff --git a/actions/detailed-review/annotate-diff.test.js b/actions/detailed-review/annotate-diff.test.js deleted file mode 100644 index e13c66068..000000000 --- a/actions/detailed-review/annotate-diff.test.js +++ /dev/null @@ -1,363 +0,0 @@ -const { annotateDiff } = require("./annotate-diff.js"); - -describe("annotateDiff", () => { - test("single file, single hunk", () => { - const diff = `diff --git a/file.js b/file.js -index abc123..def456 100644 ---- a/file.js -+++ b/file.js -@@ -1,3 +1,4 @@ - line1 - line2 -+added line - line3`; - - const result = annotateDiff(diff); - expect(result).toContain("[POS:1] line1"); - expect(result).toContain("[POS:2] line2"); - expect(result).toContain("[POS:3] +added line"); - expect(result).toContain("[POS:4] line3"); - }); - - test("single file, multiple hunks with +1 between", () => { - const diff = `diff --git a/file.js b/file.js -index abc123..def456 100644 ---- a/file.js -+++ b/file.js -@@ -1,3 +1,3 @@ - line1 --old line -+new line - line3 -@@ -10,3 +10,3 @@ - line10 --old line 11 -+new line 11 - line12`; - - const result = annotateDiff(diff); - - // First hunk - expect(result).toContain("[POS:1] line1"); - expect(result).toContain("[POS:2] -old line"); - expect(result).toContain("[POS:3] +new line"); - expect(result).toContain("[POS:4] line3"); - - // Second hunk (should start at 6, because 4 lines + 1 for between hunks) - expect(result).toContain("[POS:6] line10"); - expect(result).toContain("[POS:7] -old line 11"); - expect(result).toContain("[POS:8] +new line 11"); - expect(result).toContain("[POS:9] line12"); - }); - - test("multiple files reset position counter", () => { - const diff = `diff --git a/file1.js b/file1.js -index abc123..def456 100644 ---- a/file1.js -+++ b/file1.js -@@ -1,2 +1,2 @@ - line1 --old -+new -diff --git a/file2.js b/file2.js -index abc123..def456 100644 ---- a/file2.js -+++ b/file2.js -@@ -1,2 +1,2 @@ - first --old2 -+new2`; - - const result = annotateDiff(diff); - - // File 1 - expect(result).toContain("[POS:1] line1"); - expect(result).toContain("[POS:2] -old"); - expect(result).toContain("[POS:3] +new"); - - // File 2 - positions should reset - const file2Section = result.split("diff --git a/file2.js")[1]; - expect(file2Section).toContain("[POS:1] first"); - expect(file2Section).toContain("[POS:2] -old2"); - expect(file2Section).toContain("[POS:3] +new2"); - }); - - test("handles new file", () => { - const diff = `diff --git a/newfile.js b/newfile.js -new file mode 100644 -index 0000000..abc123 ---- /dev/null -+++ b/newfile.js -@@ -0,0 +1,3 @@ -+line1 -+line2 -+line3`; - - const result = annotateDiff(diff); - expect(result).toContain("new file mode 100644"); - expect(result).toContain("[POS:1] +line1"); - expect(result).toContain("[POS:2] +line2"); - expect(result).toContain("[POS:3] +line3"); - }); - - test("handles deleted file", () => { - const diff = `diff --git a/deleted.js b/deleted.js -deleted file mode 100644 -index abc123..0000000 ---- a/deleted.js -+++ /dev/null -@@ -1,3 +0,0 @@ --line1 --line2 --line3`; - - const result = annotateDiff(diff); - expect(result).toContain("deleted file mode 100644"); - expect(result).toContain("[POS:1] -line1"); - expect(result).toContain("[POS:2] -line2"); - expect(result).toContain("[POS:3] -line3"); - }); - - test("handles renamed file with changes", () => { - const diff = `diff --git a/old-name.js b/new-name.js -similarity index 95% -rename from old-name.js -rename to new-name.js -index abc123..def456 100644 ---- a/old-name.js -+++ b/new-name.js -@@ -1,3 +1,3 @@ - line1 --old line -+new line - line3`; - - const result = annotateDiff(diff); - expect(result).toContain("rename from old-name.js"); - expect(result).toContain("rename to new-name.js"); - expect(result).toContain("[POS:1] line1"); - expect(result).toContain("[POS:2] -old line"); - expect(result).toContain("[POS:3] +new line"); - }); - - test("handles no newline at end of file", () => { - const diff = `diff --git a/file.js b/file.js -index abc123..def456 100644 ---- a/file.js -+++ b/file.js -@@ -1,2 +1,2 @@ - line1 --old line -\\ No newline at end of file -+new line -\\ No newline at end of file`; - - const result = annotateDiff(diff); - expect(result).toContain("[POS:1] line1"); - expect(result).toContain("[POS:2] -old line"); - // Position 3 is the first "No newline" marker (not annotated but counted) - expect(result).toContain("\\ No newline at end of file"); - expect(result).toContain("[POS:4] +new line"); // Position 4 due to "No newline" at position 3 - // Position 5 is the second "No newline" marker (not annotated but counted) - expect(result).toContain("\\ No newline at end of file"); - // No newline markers should not get [POS:N] annotations - expect(result).not.toContain("[POS:3] \\"); - expect(result).not.toContain("[POS:5] \\"); - }); - - test("handles file mode changes", () => { - const diff = `diff --git a/script.sh b/script.sh -old mode 100644 -new mode 100755 -index abc123..def456 100644 ---- a/script.sh -+++ b/script.sh -@@ -1,2 +1,2 @@ - #!/bin/bash --echo "old" -+echo "new"`; - - const result = annotateDiff(diff); - expect(result).toContain("old mode 100644"); - expect(result).toContain("new mode 100755"); - expect(result).toContain("[POS:1] #!/bin/bash"); - expect(result).toContain('[POS:2] -echo "old"'); - expect(result).toContain('[POS:3] +echo "new"'); - }); - - test("empty diff returns empty", () => { - const diff = ""; - const result = annotateDiff(diff); - expect(result).toBe(""); - }); - - test("handles binary files - modified", () => { - const diff = `diff --git a/image.png b/image.png -index abc123..def456 100644 -Binary files a/image.png and b/image.png differ`; - - const result = annotateDiff(diff); - expect(result).toContain("diff --git a/image.png b/image.png"); - expect(result).toContain("Binary files a/image.png and b/image.png differ"); - // Binary files line should not be annotated - expect(result).not.toContain("[POS:"); - }); - - test("handles binary files - added", () => { - const diff = `diff --git a/newimage.png b/newimage.png -new file mode 100644 -index 0000000..abc123 -Binary files /dev/null and b/newimage.png differ`; - - const result = annotateDiff(diff); - expect(result).toContain("diff --git a/newimage.png b/newimage.png"); - expect(result).toContain("new file mode 100644"); - expect(result).toContain( - "Binary files /dev/null and b/newimage.png differ", - ); - // Binary files line should not be annotated - expect(result).not.toContain("[POS:"); - }); - - test("handles binary files - deleted", () => { - const diff = `diff --git a/oldimage.png b/oldimage.png -deleted file mode 100644 -index abc123..0000000 -Binary files a/oldimage.png and /dev/null differ`; - - const result = annotateDiff(diff); - expect(result).toContain("diff --git a/oldimage.png b/oldimage.png"); - expect(result).toContain("deleted file mode 100644"); - expect(result).toContain( - "Binary files a/oldimage.png and /dev/null differ", - ); - // Binary files line should not be annotated - expect(result).not.toContain("[POS:"); - }); - - test("handles mixed text and binary files", () => { - const diff = `diff --git a/text.js b/text.js -index abc123..def456 100644 ---- a/text.js -+++ b/text.js -@@ -1,2 +1,2 @@ - line1 --old -+new -diff --git a/image.png b/image.png -index 111111..222222 100644 -Binary files a/image.png and b/image.png differ -diff --git a/another.js b/another.js -index 333333..444444 100644 ---- a/another.js -+++ b/another.js -@@ -1,1 +1,1 @@ --foo -+bar`; - - const result = annotateDiff(diff); - - // First file (text) - expect(result).toContain("[POS:1] line1"); - expect(result).toContain("[POS:2] -old"); - expect(result).toContain("[POS:3] +new"); - - // Second file (binary) - no positions - expect(result).toContain("Binary files a/image.png and b/image.png differ"); - - // Third file (text) - positions reset - const lastFileSection = result.split("diff --git a/another.js")[1]; - expect(lastFileSection).toContain("[POS:1] -foo"); - expect(lastFileSection).toContain("[POS:2] +bar"); - }); - - test("multiple no newline markers accumulate positions", () => { - const diff = `diff --git a/file.js b/file.js -index abc123..def456 100644 ---- a/file.js -+++ b/file.js -@@ -1,3 +1,3 @@ - line1 --old1 -\\ No newline at end of file -+new1 -\\ No newline at end of file -@@ -10,3 +10,3 @@ - line10 --old2 -\\ No newline at end of file -+new2 -\\ No newline at end of file`; - - const result = annotateDiff(diff); - - // First hunk - expect(result).toContain("[POS:1] line1"); - expect(result).toContain("[POS:2] -old1"); - // Position 3 is the first "No newline" marker - expect(result).toContain("[POS:4] +new1"); - // Position 5 is the second "No newline" marker - - // Second hunk (starts at position 7 = 5 + 1 for between hunks + 1) - expect(result).toContain("[POS:7] line10"); - expect(result).toContain("[POS:8] -old2"); - // Position 9 is the third "No newline" marker - expect(result).toContain("[POS:10] +new2"); - // Position 11 is the fourth "No newline" marker - - // Verify "No newline" markers are not annotated - expect(result).not.toContain("[POS:3] \\"); - expect(result).not.toContain("[POS:5] \\"); - expect(result).not.toContain("[POS:9] \\"); - expect(result).not.toContain("[POS:11] \\"); - }); - - test("complex multi-file, multi-hunk diff", () => { - const diff = `diff --git a/src/app.js b/src/app.js -index abc123..def456 100644 ---- a/src/app.js -+++ b/src/app.js -@@ -10,4 +10,5 @@ function example() { - console.log("start"); - const x = 1; -- const y = 2; -+ const y = 3; -+ const z = 4; - return x + y; -@@ -20,3 +21,4 @@ function another() { - let a = 1; - let b = 2; -+ let c = 3; - return a + b; -diff --git a/src/util.js b/src/util.js -index 111111..222222 100644 ---- a/src/util.js -+++ b/src/util.js -@@ -1,2 +1,3 @@ -+import fs from 'fs'; - export function util() { - return true;`; - - const result = annotateDiff(diff); - - // src/app.js - first hunk - expect(result).toContain('[POS:1] console.log("start");'); - expect(result).toContain("[POS:2] const x = 1;"); - expect(result).toContain("[POS:3] - const y = 2;"); - expect(result).toContain("[POS:4] + const y = 3;"); - expect(result).toContain("[POS:5] + const z = 4;"); - expect(result).toContain("[POS:6] return x + y;"); - - // src/app.js - second hunk (7 = 6 + 1 for between hunks) - expect(result).toContain("[POS:8] let a = 1;"); - expect(result).toContain("[POS:9] let b = 2;"); - expect(result).toContain("[POS:10] + let c = 3;"); - expect(result).toContain("[POS:11] return a + b;"); - - // src/util.js - new file, positions reset - const utilSection = result.split("diff --git a/src/util.js")[1]; - expect(utilSection).toContain("[POS:1] +import fs from 'fs';"); - expect(utilSection).toContain("[POS:2] export function util() {"); - expect(utilSection).toContain("[POS:3] return true;"); - }); -}); diff --git a/actions/detailed-review/package.json b/actions/detailed-review/package.json deleted file mode 100644 index 4ca8aee1c..000000000 --- a/actions/detailed-review/package.json +++ /dev/null @@ -1,19 +0,0 @@ -{ - "name": "@continue/pr-review-scripts", - "version": "1.0.0", - "private": true, - "description": "Scripts for Continue PR Review Action", - "scripts": { - "test": "jest", - "test:watch": "jest --watch" - }, - "devDependencies": { - "jest": "^29.7.0" - }, - "jest": { - "testEnvironment": "node", - "testMatch": [ - "**/*.test.js" - ] - } -} diff --git a/actions/general-review/action.yml b/actions/general-review/action.yml index 0743fcba0..3fdb433c3 100644 --- a/actions/general-review/action.yml +++ b/actions/general-review/action.yml @@ -23,7 +23,7 @@ runs: shell: bash env: # Only move the dangerous check to env to prevent shell injection - HAS_TRIGGER_PHRASE: ${{ contains(github.event.comment.body, '@continue-general-review') }} + HAS_TRIGGER_PHRASE: ${{ contains(github.event.comment.body, '@continue-review') }} run: | # Check if this action should run based on event type and user permissions SHOULD_RUN="false" @@ -51,7 +51,7 @@ runs: echo "::notice::Skipping review - Commenter is not a team member (association: $COMMENTER_ASSOC)" fi else - echo "::notice::Skipping review - Comment does not contain @continue-general-review trigger, or is not on a PR" + echo "::notice::Skipping review - Comment does not contain @continue-review trigger, or is not on a PR" fi else echo "::notice::Skipping review - Unsupported event type: ${{ github.event_name }}" @@ -70,11 +70,97 @@ runs: shell: bash run: npm install -g @continuedev/cli@1.4.30 + - name: Post Initial Comment + if: env.SHOULD_RUN == 'true' + id: initial-comment + uses: actions/github-script@v7 + with: + script: | + const marker = ''; + + // Get PR number based on event type + let prNumber; + if (context.eventName === 'pull_request') { + prNumber = context.payload.pull_request.number; + } else { + // For issue_comment event + prNumber = context.payload.issue.number; + } + + // Check for existing comment + const { data: comments } = await github.rest.issues.listComments({ + owner: context.repo.owner, + repo: context.repo.repo, + issue_number: prNumber, + per_page: 100 + }); + + // Find existing Continue review comment + const existingComment = comments + .filter(c => c.body && c.body.includes(marker)) + .sort((a, b) => new Date(b.created_at).getTime() - new Date(a.created_at).getTime())[0]; + + // Get workflow run URL + const workflowRunUrl = `https://github.com/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId}`; + + // Create initial "review in progress" message + let initialMessage = `${marker}\n**šŸ”„ Review In Progress**\n\n`; + + if (context.eventName === 'issue_comment') { + initialMessage = `${marker}\n**šŸ”„ Review In Progress**\n\n*Triggered by @${context.payload.comment.user.login}'s request*\n\n`; + } + + initialMessage += `Continue AI is analyzing the code changes...\n\n`; + initialMessage += `šŸ“Š **Review Scope:**\n`; + initialMessage += `- Repository: ${context.repo.owner}/${context.repo.repo}\n`; + initialMessage += `- PR #${prNumber}\n\n`; + initialMessage += `ā±ļø This typically takes 1-2 minutes.\n\n`; + initialMessage += `[View live progress →](${workflowRunUrl})\n\n`; + initialMessage += `---\n`; + + if (existingComment) { + // Check if comment is less than 1 hour old + const commentAge = Date.now() - new Date(existingComment.created_at).getTime(); + const oneHour = 60 * 60 * 1000; + + if (commentAge < oneHour) { + // Update existing comment if less than 1 hour old + await github.rest.issues.updateComment({ + owner: context.repo.owner, + repo: context.repo.repo, + comment_id: existingComment.id, + body: initialMessage + }); + console.log(`Updated existing comment ${existingComment.id} to show review in progress`); + core.setOutput('comment_id', existingComment.id); + } else { + // Create new comment if older than 1 hour (preserve history) + const { data: comment } = await github.rest.issues.createComment({ + issue_number: prNumber, + owner: context.repo.owner, + repo: context.repo.repo, + body: initialMessage + }); + console.log(`Created new comment ${comment.id} showing review in progress`); + core.setOutput('comment_id', comment.id); + } + } else { + // Create new comment + const { data: comment } = await github.rest.issues.createComment({ + issue_number: prNumber, + owner: context.repo.owner, + repo: context.repo.repo, + body: initialMessage + }); + console.log(`Created new comment ${comment.id} on PR #${prNumber}`); + core.setOutput('comment_id', comment.id); + } + - name: Build PR Review Prompt if: env.SHOULD_RUN == 'true' shell: bash env: - GH_TOKEN: ${{ github.token }} + GITHUB_TOKEN: ${{ github.token }} run: | # Get PR number based on event type if [ "${{ github.event_name }}" = "pull_request" ]; then @@ -87,60 +173,58 @@ runs: # Get PR diff gh pr diff $PR_NUMBER > pr_diff.txt + # Get PR details + PR_TITLE=$(gh pr view $PR_NUMBER --json title -q .title) + PR_AUTHOR=$(gh pr view $PR_NUMBER --json author -q .author.login) + PR_BODY=$(gh pr view $PR_NUMBER --json body -q .body) + FILES_CHANGED=$(gh pr view $PR_NUMBER --json files -q '.files | length') + # Create review prompt - cat > review_prompt.txt << 'EOF' - You are conducting a code review for a pull request. Below is the git diff showing all the changes: + cat > review_prompt.txt << EOF + You are reviewing a pull request. Please provide helpful, context-aware feedback. + CONTEXT: + - Repository: ${{ github.repository }} + - PR #$PR_NUMBER: $PR_TITLE + - Files Changed: $FILES_CHANGED + - Author: $PR_AUTHOR + + REVIEW APPROACH: + 1. First, understand what this PR is trying to accomplish + 2. Check if similar patterns exist elsewhere in the codebase + 3. Focus on actual issues that affect functionality + 4. Be constructive and suggest solutions when possible + + FOCUS ON: + - Bugs that will cause failures or incorrect behavior + - Security vulnerabilities (exposed secrets, injection risks) + - Breaking changes that affect other parts of the system + - Performance issues with real impact (memory leaks, O(n²) algorithms) + - Missing tests for new features or bug fixes + - Missing documentation for APIs or complex logic + + SKIP COMMENTING ON: + - Style and formatting (handled by linters) + - Alternative approaches unless current is broken + - Minor naming unless genuinely confusing + - Trivial documentation for self-explanatory code + + Be specific with line numbers and explain why something is an issue. + + PR Description: ${PR_BODY:-No description provided} + + Code Changes: EOF - echo "--- PR DIFF START ---" >> review_prompt.txt + # Add the diff cat pr_diff.txt >> review_prompt.txt - echo "--- PR DIFF END ---" >> review_prompt.txt - + cat >> review_prompt.txt << 'EOF' - Please analyze these changes and provide a comprehensive code review. Consider: - - 1. **Code Quality**: Are there any bugs, performance issues, or code smells? - 2. **Best Practices**: Does the code follow established patterns and conventions? - 3. **Security**: Are there any potential security vulnerabilities? - 4. **Testing**: Are appropriate tests included or updated? - 5. **Documentation**: Is documentation adequate for the changes? - 6. **Architecture**: Do the changes fit well with the existing codebase structure? - - You can use the available tools to explore the codebase and understand context better. - - Format your response as a markdown code review with the following structure: - - ## Code Review Summary - - ### āœ… Strengths - - **[Aspect]**: [Description of what was done well] - - ### āš ļø Issues Found - - Only include the severity subheaders below if you actually found issues at that level: - - #### Critical - - **[Issue Title]**: [Description of critical issues that must be fixed before merging] - - #### High - - **[Issue Title]**: [Description of high-priority issues that should be fixed] - - #### Medium - - **[Issue Title]**: [Description of issues that should be addressed] - - #### Low - - **[Issue Title]**: [Description of minor issues or nice-to-have improvements] - - - ### šŸ’” Suggestions - - **[Suggestion Title]**: [Description of improvement recommendations] - - ### šŸš€ Overall Assessment - [Provide overall recommendation: APPROVE, REQUEST_CHANGES, or COMMENT] - - Only call the 'exit' tool if you find critical security vulnerabilities or bugs that would break production. + Your Review: + Please provide constructive feedback on the code changes. + Focus on issues that matter for functionality, security, and maintainability. + If the code looks good overall, acknowledge that while noting any minor suggestions. EOF - name: Run Continue CLI Review @@ -150,10 +234,12 @@ runs: CONTINUE_API_KEY: ${{ inputs.continue-api-key }} CONTINUE_ORG: ${{ inputs.continue-org }} CONTINUE_CONFIG: ${{ inputs.continue-config }} + GITHUB_TOKEN: ${{ github.token }} run: | echo "Running Continue CLI with prompt:" echo "==================================" - cat review_prompt.txt + head -n 100 review_prompt.txt + echo "... [truncated] ..." echo "==================================" echo "" @@ -189,7 +275,7 @@ runs: # Test Continue CLI availability if [ "$SKIP_CLI" != "true" ]; then echo "Testing Continue CLI..." - if ! cn --version; then + if ! which cn > /dev/null 2>&1; then echo "Warning: Continue CLI not found or not working" cat > code_review.md << 'EOF' ## Code Review Summary @@ -202,7 +288,8 @@ runs: EOF echo "SKIP_CLI=true" >> $GITHUB_ENV else - echo "Continue CLI version: $(cn --version)" + echo "Continue CLI found at: $(which cn)" + echo "Continue CLI version: $(cn --version 2>/dev/null || echo 'version check failed')" fi fi @@ -210,30 +297,78 @@ runs: if [ "$SKIP_CLI" != "true" ]; then echo "Executing Continue CLI with config: $CONTINUE_ORG/$CONTINUE_CONFIG" - # Write prompt to temp file for better handling - PROMPT_FILE="/tmp/continue-prompt-$.txt" + # Write prompt to temp file for headless mode + PROMPT_FILE="/tmp/continue-review-$RANDOM.txt" cp review_prompt.txt "$PROMPT_FILE" + echo "Prompt file: $PROMPT_FILE" + echo "Prompt length: $(wc -c < "$PROMPT_FILE") characters" - # Use timeout to prevent hanging (240 seconds = 4 minutes) - if ! timeout 240 cn --config "$CONTINUE_ORG/$CONTINUE_CONFIG" -p "@$PROMPT_FILE" --allow Bash > code_review.md 2>cli_error.log; then - echo "Error: Continue CLI command failed" - echo "CLI error log:" - cat cli_error.log + # Use timeout to prevent hanging (360 seconds = 6 minutes) + echo "Executing command: cn --config $CONTINUE_ORG/$CONTINUE_CONFIG -p @$PROMPT_FILE --allow Bash" - # Create fallback review - cat > code_review.md << 'EOF' + if timeout 360 cn --config "$CONTINUE_ORG/$CONTINUE_CONFIG" -p "@$PROMPT_FILE" --allow Bash > code_review_raw.md 2>cli_error.log; then + echo "Continue CLI completed successfully" + echo "Raw output length: $(wc -c < code_review_raw.md) characters" + + # Clean up ANSI codes if any + sed 's/\x1b\[[0-9;]*m//g' code_review_raw.md > code_review.md + + echo "Cleaned output length: $(wc -c < code_review.md) characters" + echo "First 500 chars of output:" + head -c 500 code_review.md + echo "" + + # Check if output is empty + if [ ! -s code_review.md ]; then + echo "Warning: Continue CLI returned empty output" + cat > code_review.md << 'EOF' ## Code Review Summary - āš ļø AI review failed due to service initialization issues. Please check the Continue API key and configuration. + āš ļø Continue CLI returned an empty response. Please check the configuration. + EOF + fi + else + echo "Error: Continue CLI command failed with exit code $?" + echo "CLI error log:" + cat cli_error.log + + # Check for specific error patterns + if grep -q "not found\|ENOENT" cli_error.log 2>/dev/null; then + cat > code_review.md << 'EOF' + ## Code Review Summary + + āš ļø Continue CLI is not properly installed. Please ensure @continuedev/cli is installed globally. + EOF + elif grep -q "config\|assistant" cli_error.log 2>/dev/null; then + cat > code_review.md << 'EOF' + ## Code Review Summary + + āš ļø Continue configuration error. Please verify that the assistant exists in Continue Hub. + EOF + elif grep -q "api\|auth" cli_error.log 2>/dev/null; then + cat > code_review.md << 'EOF' + ## Code Review Summary + + āš ļø Continue API authentication failed. Please check your CONTINUE_API_KEY. + EOF + else + cat > code_review.md << 'EOF' + ## Code Review Summary + + āš ļø AI review failed. Please check the Continue API key and configuration. ### Troubleshooting - Verify the CONTINUE_API_KEY secret is set correctly - Check that the organization and config path are valid - Ensure the Continue service is accessible EOF + fi + fi + + # Clean up temp file + rm -f "$PROMPT_FILE" else - echo "Review generated successfully" - fi + echo "Review generation successfully completed" fi - name: Upload Review Results @@ -247,7 +382,7 @@ runs: pr_diff.txt retention-days: 30 - - name: Comment PR with Review + - name: Update Comment with Review if: env.SHOULD_RUN == 'true' && always() uses: actions/github-script@v7 with: @@ -256,13 +391,15 @@ runs: try { let reviewContent = ''; - + if (fs.existsSync('code_review.md') && fs.statSync('code_review.md').size > 0) { reviewContent = fs.readFileSync('code_review.md', 'utf8'); } else { - reviewContent = 'āš ļø AI review completed but no review output was generated. Check the action logs for details.'; + // Build direct link to workflow logs + const workflowRunUrl = `https://github.com/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId}`; + reviewContent = `āš ļø AI review completed but no review output was generated.\n\n**Likely cause:** Expired CONTINUE_API_KEY or missing continuedev/review-bot assistant\n\n[šŸ“‹ View workflow logs](${workflowRunUrl}) for details.`; } - + // Get PR number based on event type let prNumber; if (context.eventName === 'pull_request') { @@ -277,17 +414,115 @@ runs: reviewContent = `*Triggered by @${context.payload.comment.user.login}'s request*\n\n${reviewContent}`; } - // Add instructions for re-review - reviewContent += '\n\n---\n*šŸ’” To request a new review, comment `@continue-general-review`*'; + // Add footer with timestamp and branding + const timestamp = new Date().toISOString(); + reviewContent += `\n\n---\n`; - // Create new comment - await github.rest.issues.createComment({ - issue_number: prNumber, - owner: context.repo.owner, - repo: context.repo.repo, - body: reviewContent - }); - console.log(`Successfully created new comment on PR #${prNumber}`); + // Look for existing review comment to update (sticky comment) + const marker = ''; + + // Try to get comment_id from the initial comment step + const initialCommentId = '${{ steps.initial-comment.outputs.comment_id }}'; + + if (initialCommentId && initialCommentId !== '') { + // We have the comment ID from the initial step, use it directly + reviewContent = `${marker}\n**āœ… Review Complete**\n\n${reviewContent}`; + + try { + await github.rest.issues.updateComment({ + owner: context.repo.owner, + repo: context.repo.repo, + comment_id: parseInt(initialCommentId), + body: reviewContent + }); + console.log(`Updated comment ${initialCommentId} with review results`); + } catch (updateError) { + console.log(`Failed to update comment ${initialCommentId}, will search for it instead:`, updateError.message); + + // Fallback: search for the comment + const { data: comments } = await github.rest.issues.listComments({ + owner: context.repo.owner, + repo: context.repo.repo, + issue_number: prNumber, + per_page: 100 + }); + + // Find existing Continue review comment + const existingComment = comments + .filter(c => c.body && c.body.includes(marker)) + .sort((a, b) => new Date(b.created_at).getTime() - new Date(a.created_at).getTime())[0]; + + if (existingComment) { + await github.rest.issues.updateComment({ + owner: context.repo.owner, + repo: context.repo.repo, + comment_id: existingComment.id, + body: reviewContent + }); + console.log(`Updated existing comment ${existingComment.id} via search`); + } else { + // Create new comment as last resort + await github.rest.issues.createComment({ + issue_number: prNumber, + owner: context.repo.owner, + repo: context.repo.repo, + body: reviewContent + }); + console.log(`Created new comment on PR #${prNumber} as fallback`); + } + } + } else { + // No initial comment ID, search for existing comment + const { data: comments } = await github.rest.issues.listComments({ + owner: context.repo.owner, + repo: context.repo.repo, + issue_number: prNumber, + per_page: 100 + }); + + // Find existing Continue review comment + const existingComment = comments + .filter(c => c.body && c.body.includes(marker)) + .sort((a, b) => new Date(b.created_at).getTime() - new Date(a.created_at).getTime())[0]; + + // Add marker and review status + reviewContent = `${marker}\n**āœ… Review Complete**\n\n${reviewContent}`; + + if (existingComment) { + // Check if comment is less than 1 hour old + const commentAge = Date.now() - new Date(existingComment.created_at).getTime(); + const oneHour = 60 * 60 * 1000; + + if (commentAge < oneHour) { + // Update existing comment if less than 1 hour old + await github.rest.issues.updateComment({ + owner: context.repo.owner, + repo: context.repo.repo, + comment_id: existingComment.id, + body: reviewContent + }); + console.log(`Updated existing comment ${existingComment.id} (${Math.round(commentAge / 1000 / 60)} minutes old)`); + } else { + // Create new comment if older than 1 hour (preserve history) + await github.rest.issues.createComment({ + issue_number: prNumber, + owner: context.repo.owner, + repo: context.repo.repo, + body: reviewContent + }); + console.log(`Created new comment (existing comment was ${Math.round(commentAge / 1000 / 60)} minutes old)`); + } + } else { + // Create new comment + await github.rest.issues.createComment({ + issue_number: prNumber, + owner: context.repo.owner, + repo: context.repo.repo, + body: reviewContent + }); + console.log(`Created new comment on PR #${prNumber}`); + } + } } catch (error) { console.log('Failed to post comment:', error.message); console.log('Error details:', error);