Update continue-review.yaml
This commit is contained in:
parent
82c7cc24bd
commit
2b384e7fb5
1 changed files with 21 additions and 111 deletions
132
.github/workflows/continue-review.yaml
vendored
132
.github/workflows/continue-review.yaml
vendored
|
|
@ -1,31 +1,8 @@
|
|||
name: Continue CLI Code Review
|
||||
|
||||
on:
|
||||
workflow_call:
|
||||
inputs:
|
||||
assistant:
|
||||
description: "Assistant configuration to use"
|
||||
required: false
|
||||
default: "nate/default-assistant"
|
||||
type: string
|
||||
prompt:
|
||||
description: "Custom prompt to use instead of the default PR review"
|
||||
required: false
|
||||
type: string
|
||||
secrets:
|
||||
CONTINUE_API_KEY:
|
||||
required: true
|
||||
workflow_dispatch:
|
||||
inputs:
|
||||
assistant:
|
||||
description: "Assistant configuration to use"
|
||||
required: false
|
||||
default: "nate/default-assistant"
|
||||
type: string
|
||||
prompt:
|
||||
description: "Custom prompt to use instead of the default PR review"
|
||||
required: false
|
||||
type: string
|
||||
pull_request:
|
||||
types: [opened, synchronize, reopened]
|
||||
|
||||
permissions:
|
||||
contents: read
|
||||
|
|
@ -51,32 +28,22 @@ jobs:
|
|||
- name: Install Continue CLI
|
||||
run: npm install -g @continuedev/cli@1.4.25
|
||||
|
||||
- name: Build PR diff prompt
|
||||
if: github.event_name == 'pull_request' || (github.event_name == 'workflow_run' && github.event.workflow_run.event == 'pull_request')
|
||||
- name: Build PR Review Prompt
|
||||
run: |
|
||||
# Get PR number - different methods depending on trigger
|
||||
if [ "${{ github.event_name }}" = "pull_request" ]; then
|
||||
PR_NUMBER="${{ github.event.number }}"
|
||||
else
|
||||
# For workflow_call triggered by PR, we need to get it from context
|
||||
PR_NUMBER=$(jq -r '.pull_request.number' "$GITHUB_EVENT_PATH" 2>/dev/null || echo "")
|
||||
fi
|
||||
|
||||
if [ -n "$PR_NUMBER" ] && [ "$PR_NUMBER" != "null" ]; then
|
||||
# Get PR diff using GitHub CLI
|
||||
gh pr diff $PR_NUMBER > pr_diff.txt
|
||||
|
||||
# Create comprehensive prompt
|
||||
cat > review_prompt.txt << 'EOF'
|
||||
# Get PR diff
|
||||
gh pr diff ${{ github.event.number }} > pr_diff.txt
|
||||
|
||||
# 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:
|
||||
|
||||
EOF
|
||||
|
||||
echo "--- PR DIFF START ---" >> review_prompt.txt
|
||||
cat pr_diff.txt >> review_prompt.txt
|
||||
echo "--- PR DIFF END ---" >> review_prompt.txt
|
||||
|
||||
cat >> review_prompt.txt << 'EOF'
|
||||
|
||||
echo "--- PR DIFF START ---" >> review_prompt.txt
|
||||
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:
|
||||
|
||||
|
|
@ -107,56 +74,9 @@ jobs:
|
|||
|
||||
Only call the 'exit' tool if you find critical security vulnerabilities or bugs that would break production.
|
||||
EOF
|
||||
else
|
||||
echo "Could not determine PR number, using generic prompt"
|
||||
cat > review_prompt.txt << 'EOF'
|
||||
Please review the recent changes to this codebase and provide feedback on code quality, potential issues, and suggestions for improvement.
|
||||
|
||||
Format your response as a markdown code review.
|
||||
EOF
|
||||
fi
|
||||
env:
|
||||
GH_TOKEN: ${{ github.token }}
|
||||
|
||||
- name: Build custom prompt
|
||||
if: inputs.prompt != ''
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ github.token }}
|
||||
run: |
|
||||
# Get PR number for custom prompts too
|
||||
if [ "${{ github.event_name }}" = "pull_request" ]; then
|
||||
PR_NUMBER="${{ github.event.number }}"
|
||||
else
|
||||
# For workflow_call triggered by PR, we need to get it from context
|
||||
PR_NUMBER=$(jq -r '.pull_request.number' "$GITHUB_EVENT_PATH" 2>/dev/null || echo "")
|
||||
fi
|
||||
|
||||
if [ -n "$PR_NUMBER" ] && [ "$PR_NUMBER" != "null" ]; then
|
||||
# Get PR diff using GitHub CLI
|
||||
gh pr diff $PR_NUMBER > pr_diff.txt
|
||||
|
||||
# Create custom prompt with diff included
|
||||
echo "${{ inputs.prompt }}" > review_prompt.txt
|
||||
echo "" >> review_prompt.txt
|
||||
echo "Below is the git diff showing all the changes:" >> review_prompt.txt
|
||||
echo "" >> review_prompt.txt
|
||||
echo "--- PR DIFF START ---" >> review_prompt.txt
|
||||
cat pr_diff.txt >> review_prompt.txt
|
||||
echo "--- PR DIFF END ---" >> review_prompt.txt
|
||||
else
|
||||
echo "${{ inputs.prompt }}" > review_prompt.txt
|
||||
fi
|
||||
|
||||
- name: Build default prompt for non-PR triggers
|
||||
if: inputs.prompt == '' && github.event_name != 'pull_request' && (github.event_name != 'workflow_run' || github.event.workflow_run.event != 'pull_request')
|
||||
run: |
|
||||
cat > review_prompt.txt << 'EOF'
|
||||
Please review the recent changes to this codebase and provide feedback on code quality, potential issues, and suggestions for improvement. You do not need to acknowledge what was done well.
|
||||
|
||||
Format your response as a markdown code review with each comment having only a short description about the problem and suggested solution, each being separated by "\n\n---\n\n".
|
||||
|
||||
EOF
|
||||
|
||||
- name: Run Continue CLI Review
|
||||
run: |
|
||||
echo "Running Continue CLI with prompt:"
|
||||
|
|
@ -165,8 +85,8 @@ jobs:
|
|||
echo "=================================="
|
||||
echo ""
|
||||
|
||||
# Run the CLI with the generated prompt and pipe output to code_review.md
|
||||
cat review_prompt.txt | cn --auto --config "${{ inputs.assistant }}" -p > code_review.md
|
||||
# Run the CLI with hardcoded assistant and pipe output to code_review.md
|
||||
cat review_prompt.txt | cn --auto --config "nate/default-assistant" -p > code_review.md
|
||||
env:
|
||||
CONTINUE_API_KEY: ${{ secrets.CONTINUE_API_KEY }}
|
||||
|
||||
|
|
@ -182,7 +102,7 @@ jobs:
|
|||
retention-days: 30
|
||||
|
||||
- name: Comment PR with Review
|
||||
if: always() && (github.event_name == 'pull_request' || (github.event_name == 'workflow_run' && github.event.workflow_run.event == 'pull_request'))
|
||||
if: always()
|
||||
uses: actions/github-script@v7
|
||||
with:
|
||||
script: |
|
||||
|
|
@ -197,25 +117,15 @@ jobs:
|
|||
reviewContent = '⚠️ AI review completed but no review output was generated. Check the action logs for details.';
|
||||
}
|
||||
|
||||
// Get PR number
|
||||
let prNumber;
|
||||
if (context.payload.pull_request) {
|
||||
prNumber = context.payload.pull_request.number;
|
||||
} else if (context.payload.workflow_run && context.payload.workflow_run.pull_requests && context.payload.workflow_run.pull_requests.length > 0) {
|
||||
prNumber = context.payload.workflow_run.pull_requests[0].number;
|
||||
}
|
||||
|
||||
if (!prNumber) {
|
||||
console.log('Could not determine PR number for commenting');
|
||||
return;
|
||||
}
|
||||
const prNumber = context.payload.pull_request.number;
|
||||
|
||||
// Unique identifier for our bot comments
|
||||
const botSignature = '<!-- continue-cli-review -->';
|
||||
const newComment = `${botSignature}\n${reviewContent}`;
|
||||
|
||||
// Get all comments on the PR
|
||||
const { data: comments } = await github.rest.issues.listComments({ per_page: 100,
|
||||
const { data: comments } = await github.rest.issues.listComments({
|
||||
per_page: 100,
|
||||
issue_number: prNumber,
|
||||
owner: context.repo.owner,
|
||||
repo: context.repo.repo,
|
||||
|
|
@ -250,4 +160,4 @@ jobs:
|
|||
console.log('Error details:', error);
|
||||
}
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ github.token }}
|
||||
GITHUB_TOKEN: ${{ github.token }}
|
||||
Loading…
Add table
Reference in a new issue