diff --git a/.github/workflows/code-review-debug.yml b/.github/workflows/code-review-debug.yml new file mode 100644 index 00000000000..944cd4906b9 --- /dev/null +++ b/.github/workflows/code-review-debug.yml @@ -0,0 +1,233 @@ +name: Continue Code Review (Debug) +on: + pull_request: + types: [opened, synchronize, ready_for_review] + issue_comment: + types: [created] + +permissions: + contents: read + pull-requests: write + issues: write + +jobs: + review: + if: | + github.event_name == 'pull_request' || + (github.event_name == 'issue_comment' && + github.event.issue.pull_request && + contains(github.event.comment.body, '@review-bot')) + runs-on: ubuntu-latest + steps: + - name: Checkout repository + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Generate App Token (Optional) + if: vars.CONTINUE_APP_ID != '' && secrets.CONTINUE_APP_PRIVATE_KEY != '' + id: generate_token + uses: actions/create-github-app-token@v1 + with: + app-id: ${{ vars.CONTINUE_APP_ID }} + private-key: ${{ secrets.CONTINUE_APP_PRIVATE_KEY }} + + - name: Setup Node.js + uses: actions/setup-node@v4 + with: + node-version: '20' + + - name: Validate Continue API Key + run: | + echo "🔍 Checking if CONTINUE_API_KEY is set..." + if [ -z "${{ secrets.CONTINUE_API_KEY }}" ]; then + echo "❌ ERROR: CONTINUE_API_KEY secret is not set!" + echo "Please add it in Settings → Secrets and variables → Actions" + echo "Get your key from: https://hub.continue.dev/settings/api-keys" + exit 1 + else + echo "✅ CONTINUE_API_KEY is set (length: ${#CONTINUE_API_KEY})" + fi + env: + CONTINUE_API_KEY: ${{ secrets.CONTINUE_API_KEY }} + + - name: Install Continue CLI + run: | + echo "đŸ“Ļ Installing Continue CLI..." + npm i -g @continuedev/cli + echo "✅ Continue CLI installed" + echo "🔍 Checking Continue CLI version..." + cn --version || echo "âš ī¸ Warning: Could not get CLI version" + + - name: Verify Continue CLI Installation + run: | + echo "🔍 Verifying Continue CLI installation..." + which cn || echo "❌ ERROR: cn command not found in PATH" + cn --help || echo "❌ ERROR: cn --help failed" + + - name: Get PR Details + id: pr + env: + GH_TOKEN: ${{ steps.generate_token.outputs.token || github.token }} + run: | + echo "🔍 Getting PR details..." + if [ "${{ github.event_name }}" = "issue_comment" ]; then + PR_NUMBER=$(jq -r .issue.number "$GITHUB_EVENT_PATH") + else + PR_NUMBER=$(jq -r .pull_request.number "$GITHUB_EVENT_PATH") + fi + + echo "PR_NUMBER=$PR_NUMBER" >> $GITHUB_OUTPUT + echo "✅ PR Number: $PR_NUMBER" + + echo "đŸ“Ĩ Fetching PR diff..." + gh pr diff $PR_NUMBER > pr.diff || { + echo "❌ ERROR: Failed to fetch PR diff" + exit 1 + } + echo "✅ PR diff saved ($(wc -l < pr.diff) lines)" + + echo "📁 Fetching changed files..." + gh pr view $PR_NUMBER --json files -q '.files[].path' > changed_files.txt || { + echo "❌ ERROR: Failed to fetch changed files" + exit 1 + } + echo "✅ Changed files saved ($(wc -l < changed_files.txt) files)" + + echo "📋 Changed files:" + cat changed_files.txt + + - name: Check for Custom Rules + run: | + echo "🔍 Checking for custom rules in .continue/rules/..." + if [ -d ".continue/rules" ]; then + echo "✅ Found .continue/rules directory" + echo "📋 Custom rules:" + find .continue/rules -name "*.md" -o -name "*.txt" || echo "No rule files found" + else + echo "â„šī¸ No custom rules directory found (this is optional)" + fi + + - name: Run Continue Review + env: + CONTINUE_API_KEY: ${{ secrets.CONTINUE_API_KEY }} + run: | + echo "🤖 Running Continue code review..." + + CHANGED_FILES=$(cat changed_files.txt | tr '\n' ' ') + DIFF=$(cat pr.diff) + + # Check if running from issue comment + if [ "${{ github.event_name }}" = "issue_comment" ]; then + COMMENT_BODY="${{ github.event.comment.body }}" + CUSTOM_REQUEST=$(echo "$COMMENT_BODY" | sed -n 's/.*@review-bot check for \(.*\)/\1/p') + if [ -n "$CUSTOM_REQUEST" ]; then + echo "📝 Custom review request: $CUSTOM_REQUEST" + FOCUS="Focus specifically on: $CUSTOM_REQUEST" + fi + fi + + PROMPT="You are an expert code reviewer. Review the following pull request changes. + +Changed files: +$CHANGED_FILES + +Diff: +\`\`\`diff +$DIFF +\`\`\` + +${FOCUS:-Review the code for potential issues, bugs, security concerns, and improvements.} + +Provide your review in the following markdown format: + +## Summary +Brief overview of the changes + +## Key Findings +- List any issues, bugs, or security concerns +- Suggest improvements + +## Positive Observations +- Note good practices + +## Recommendations +- Actionable suggestions" + + echo "🔍 Prompt length: ${#PROMPT} characters" + echo "🔍 Running: cn --config continuedev/code-reviewer -p \"...\" --auto" + + cn --config continuedev/code-reviewer \ + -p "$PROMPT" \ + --auto > review_output.md 2>&1 || { + EXIT_CODE=$? + echo "❌ ERROR: Continue review failed with exit code $EXIT_CODE" + echo "📋 Output:" + cat review_output.md + echo "" + echo "🔍 Debugging information:" + echo " - Continue API Key length: ${#CONTINUE_API_KEY}" + echo " - Config: continuedev/code-reviewer" + echo " - Prompt length: ${#PROMPT}" + echo "" + echo "💡 Common issues:" + echo " 1. Invalid or expired CONTINUE_API_KEY" + echo " 2. Assistant 'continuedev/code-reviewer' not found or not accessible" + echo " 3. Continue Hub account issues" + echo "" + echo "🔧 Troubleshooting steps:" + echo " 1. Verify your API key at https://hub.continue.dev/settings/api-keys" + echo " 2. Check that you have access to the code-reviewer assistant" + echo " 3. Try creating a custom assistant for code reviews" + exit $EXIT_CODE + } + + echo "✅ Review completed successfully" + echo "📋 Review output:" + cat review_output.md + + - name: Post Review Comment + env: + GH_TOKEN: ${{ steps.generate_token.outputs.token || github.token }} + run: | + echo "đŸ’Ŧ Posting review comment..." + + PR_NUMBER="${{ steps.pr.outputs.PR_NUMBER }}" + REVIEW_BODY=$(cat review_output.md) + + COMMENT_BODY="## 🤖 AI Code Review + +$REVIEW_BODY + +--- +*Powered by Continue â€ĸ Need a focused review? Comment \`@review-bot check for [specific concern]\`*" + + # Check for existing review comment + EXISTING_COMMENT=$(gh api \ + repos/${{ github.repository }}/issues/$PR_NUMBER/comments \ + --jq '.[] | select(.body | contains("🤖 AI Code Review")) | .id' \ + | head -n 1) + + if [ -n "$EXISTING_COMMENT" ]; then + echo "🔄 Updating existing comment (ID: $EXISTING_COMMENT)..." + gh api \ + --method PATCH \ + repos/${{ github.repository }}/issues/comments/$EXISTING_COMMENT \ + -f body="$COMMENT_BODY" + echo "✅ Comment updated" + else + echo "✨ Creating new comment..." + gh pr comment $PR_NUMBER --body "$COMMENT_BODY" + echo "✅ Comment created" + fi + + - name: Upload Artifacts (Debug) + if: always() + uses: actions/upload-artifact@v4 + with: + name: review-debug-artifacts + path: | + pr.diff + changed_files.txt + review_output.md + retention-days: 7 diff --git a/.github/workflows/continue-general-review.yaml b/.github/workflows/continue-general-review.yaml index 34611923f3b..a410d774e3f 100644 --- a/.github/workflows/continue-general-review.yaml +++ b/.github/workflows/continue-general-review.yaml @@ -1,11 +1,8 @@ name: Continue General Review on: - push: - branches: - - main pull_request: - types: [opened, ready_for_review] + types: [opened, ready_for_review, synchronize] issue_comment: types: [created] @@ -26,3 +23,4 @@ jobs: continue-api-key: ${{ secrets.CONTINUE_API_KEY }} continue-org: "continuedev" continue-agent: "empty-agent" + github-token: ${{ github.token }} diff --git a/TROUBLESHOOTING_REVIEW_BOT.md b/TROUBLESHOOTING_REVIEW_BOT.md new file mode 100644 index 00000000000..d1a53926e82 --- /dev/null +++ b/TROUBLESHOOTING_REVIEW_BOT.md @@ -0,0 +1,187 @@ +# Continue PR Review Bot - Troubleshooting Guide + +## Quick Diagnostic Steps + +Use the enhanced debug workflow to identify issues: + +1. **Copy the diagnostic workflow** to the target repository: + + ```bash + cp .github/workflows/code-review-debug.yml /path/to/siblings-write/.github/workflows/ + ``` + +2. **Commit and push** the workflow to trigger it on the next PR + +3. **Review the detailed logs** - each step now includes: + - ✅ Success indicators + - ❌ Error messages with context + - 🔍 Debug information + - 💡 Troubleshooting hints + +## Common Issues and Solutions + +### 1. Missing or Invalid API Key + +**Symptoms:** + +- Exit code 1 +- Authentication failures +- "API key not found" errors + +**Solution:** + +```bash +# 1. Get a fresh API key +# Visit: https://hub.continue.dev/settings/api-keys + +# 2. Add to repository secrets +# Go to: Repository Settings → Secrets and variables → Actions +# Create secret: CONTINUE_API_KEY +# Paste your key (starts with "cnt_...") +``` + +### 2. Assistant Not Found + +**Symptoms:** + +- "Config not found" errors +- "continuedev/code-reviewer" not accessible + +**Solution:** + +- Option A: Use the default assistant by removing `--config` flag +- Option B: Create your own assistant at hub.continue.dev +- Option C: Use a different public assistant + +**Modify the workflow:** + +```yaml +# Instead of: +cn --config continuedev/code-reviewer -p "$PROMPT" --auto + +# Try: +cn -p "$PROMPT" --auto # Uses default assistant +# OR +cn --config your-username/your-assistant -p "$PROMPT" --auto +``` + +### 3. CLI Installation Failures + +**Symptoms:** + +- npm install errors +- "cn command not found" + +**Solution:** +The debug workflow checks: + +- CLI installation success +- CLI version +- Command availability + +If this fails, check: + +- Network connectivity in GitHub Actions +- npm registry access +- Node.js version compatibility + +### 4. GitHub Permissions + +**Symptoms:** + +- Cannot post comments +- Cannot read PR details + +**Solution:** +Ensure workflow has correct permissions: + +```yaml +permissions: + contents: read + pull-requests: write + issues: write +``` + +## Debug Workflow Features + +The diagnostic workflow (`code-review-debug.yml`) includes: + +### Enhanced Validation + +- ✅ Validates API key presence before running +- ✅ Checks CLI installation and version +- ✅ Verifies PR data fetching +- ✅ Lists changed files for transparency + +### Better Error Messages + +- Detailed error context with exit codes +- Troubleshooting hints inline +- Common issue checklists +- Links to relevant documentation + +### Debug Artifacts + +Uploads artifacts on every run (even failures): + +- `pr.diff` - The PR changes +- `changed_files.txt` - List of modified files +- `review_output.md` - Continue CLI output + +**Access artifacts:** + +- Go to Actions → Workflow run → Artifacts section +- Download "review-debug-artifacts.zip" + +## Step-by-Step Debugging Process + +1. **Run the debug workflow** on a test PR + +2. **Check each step's output:** + + - Look for ❌ error indicators + - Read the specific error messages + - Follow the inline troubleshooting hints + +3. **Common failure points (in order):** + + - [ ] API key validation (Step: Validate Continue API Key) + - [ ] CLI installation (Step: Install Continue CLI) + - [ ] CLI verification (Step: Verify Continue CLI Installation) + - [ ] PR data fetching (Step: Get PR Details) + - [ ] Continue review execution (Step: Run Continue Review) + - [ ] Comment posting (Step: Post Review Comment) + +4. **Download artifacts** to inspect: + - Review the exact prompt sent to Continue + - Check the PR diff format + - Verify changed files list + +## Testing the Fix + +After applying fixes: + +1. Create a test PR or comment `@review-bot check for syntax errors` +2. Monitor the workflow run in real-time +3. Look for all ✅ indicators +4. Verify the review comment appears on the PR + +## Additional Resources + +- Continue Documentation: https://docs.continue.dev/guides/github-pr-review-bot +- Continue Hub: https://hub.continue.dev +- API Keys: https://hub.continue.dev/settings/api-keys +- CLI Repository: https://github.com/continuedev/continue/tree/main/packages/cli + +## Need More Help? + +If the debug workflow still shows errors: + +1. **Check the Continue CLI logs** in the artifact download +2. **Verify your Continue Hub account** has active credits/access +3. **Test the API key locally:** + ```bash + export CONTINUE_API_KEY="your_key_here" + echo "test" | cn -p "Review this text" --auto + ``` +4. **Open an issue** with the debug workflow output attached diff --git a/actions/general-review/action.yml b/actions/general-review/action.yml index d5e6a7b1773..96b44b76cc1 100644 --- a/actions/general-review/action.yml +++ b/actions/general-review/action.yml @@ -12,6 +12,10 @@ inputs: continue-agent: description: 'Agent path to use (e.g., "myorg/review-bot")' required: true + github-token: + description: "GitHub token for API access" + required: false + default: ${{ github.token }} runs: using: "composite" @@ -23,6 +27,7 @@ runs: id: auth-check uses: actions/github-script@v7 with: + github-token: ${{ inputs.github-token || github.token }} script: | let shouldRun = false; let skipReason = ''; @@ -120,6 +125,7 @@ runs: id: initial-comment uses: actions/github-script@v7 with: + github-token: ${{ inputs.github-token || github.token }} script: | const marker = ''; @@ -205,7 +211,7 @@ runs: if: env.SHOULD_RUN == 'true' shell: bash env: - GITHUB_TOKEN: ${{ github.token }} + GITHUB_TOKEN: ${{ inputs.github-token || github.token }} run: | # Get PR number based on event type if [ "${{ github.event_name }}" = "pull_request" ]; then @@ -228,7 +234,7 @@ runs: CONTINUE_API_KEY: ${{ inputs.continue-api-key }} CONTINUE_ORG: ${{ inputs.continue-org }} CONTINUE_AGENT: ${{ inputs.continue-agent }} - GITHUB_TOKEN: ${{ github.token }} + GITHUB_TOKEN: ${{ inputs.github-token || github.token }} run: | echo "Running Continue CLI with prompt:" echo "==================================" @@ -339,6 +345,7 @@ runs: if: env.SHOULD_RUN == 'true' && always() uses: actions/github-script@v7 with: + github-token: ${{ inputs.github-token || github.token }} script: | const fs = require('fs');