feat: custom gh action
This commit is contained in:
parent
bdab2cb85e
commit
4740bd8362
2 changed files with 356 additions and 0 deletions
152
pr-review-action/README.md
Normal file
152
pr-review-action/README.md
Normal file
|
|
@ -0,0 +1,152 @@
|
|||
# Continue PR Review Action
|
||||
|
||||
A GitHub Action that provides automated code review for pull requests using Continue CLI.
|
||||
|
||||
## Usage
|
||||
|
||||
Add this workflow to your repository at `.github/workflows/pr-review.yml`:
|
||||
|
||||
```yaml
|
||||
name: PR 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: actions/checkout@v4
|
||||
with:
|
||||
fetch-depth: 0
|
||||
- uses: continuedev/continue/pr-review-action@v1
|
||||
with:
|
||||
continue-api-key: ${{ secrets.CONTINUE_API_KEY }}
|
||||
continue-org: 'your-org-name'
|
||||
continue-config: 'your-org-name/review-bot'
|
||||
```
|
||||
|
||||
The action automatically handles authorization checks and only runs for:
|
||||
- PRs opened or marked ready by team members (OWNER, MEMBER, COLLABORATOR)
|
||||
- Comments containing `@continue-review` from team members
|
||||
|
||||
## Inputs
|
||||
|
||||
| Input | Description | Required |
|
||||
|-------|-------------|----------|
|
||||
| `continue-api-key` | API key for Continue service | Yes |
|
||||
| `continue-org` | Organization for Continue config | Yes |
|
||||
| `continue-config` | Config path (e.g., "myorg/review-bot") | Yes |
|
||||
|
||||
## Setup Requirements
|
||||
|
||||
### 1. Continue API Key
|
||||
Add your Continue API key as a secret named `CONTINUE_API_KEY` in your repository:
|
||||
1. Go to your repository's Settings
|
||||
2. Navigate to Secrets and variables → Actions
|
||||
3. Click "New repository secret"
|
||||
4. Name: `CONTINUE_API_KEY`
|
||||
5. Value: Your Continue API key
|
||||
|
||||
### 2. Continue Configuration
|
||||
Set up your review bot configuration in Continue:
|
||||
1. Create a configuration for your organization
|
||||
2. Configure the review bot settings
|
||||
3. Note your organization name and config path
|
||||
|
||||
### 3. Workflow Permissions
|
||||
The workflow requires these permissions:
|
||||
- `contents: read` - To checkout and read repository code
|
||||
- `pull-requests: write` - To post review comments on PRs
|
||||
- `issues: write` - To respond to comment triggers
|
||||
|
||||
## Triggering Reviews
|
||||
|
||||
The action can be triggered in two ways:
|
||||
|
||||
### Automatic Triggers
|
||||
- When a PR is opened by a team member (OWNER, MEMBER, or COLLABORATOR)
|
||||
- When a PR is marked as "ready for review" by a team member
|
||||
|
||||
### Manual Trigger
|
||||
Team members can trigger a review by commenting `@continue-review` on any pull request.
|
||||
|
||||
## Versioning
|
||||
|
||||
This action follows semantic versioning. We recommend using the major version tag for automatic updates:
|
||||
|
||||
- `@v1` - Automatically uses the latest v1.x.x release (recommended)
|
||||
- `@v1.0.0` - Pins to a specific version
|
||||
- `@main` - Uses the latest code from the main branch (not recommended for production)
|
||||
|
||||
## Minimal Example
|
||||
|
||||
This is the simplest possible configuration:
|
||||
|
||||
```yaml
|
||||
name: PR Review
|
||||
on: [pull_request, issue_comment]
|
||||
|
||||
permissions:
|
||||
contents: read
|
||||
pull-requests: write
|
||||
issues: write
|
||||
|
||||
jobs:
|
||||
review:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
with:
|
||||
fetch-depth: 0
|
||||
- uses: continuedev/continue/pr-review-action@v1
|
||||
with:
|
||||
continue-api-key: ${{ secrets.CONTINUE_API_KEY }}
|
||||
continue-org: 'acme-corp'
|
||||
continue-config: 'acme-corp/review-bot'
|
||||
```
|
||||
|
||||
## How It Works
|
||||
|
||||
1. The action checks out your repository code
|
||||
2. Installs the Continue CLI (v1.4.25)
|
||||
3. Fetches the PR diff using GitHub CLI
|
||||
4. Generates a comprehensive review prompt
|
||||
5. Runs the Continue CLI with your specified configuration
|
||||
6. Posts the review as a comment on the PR
|
||||
|
||||
## Review Output
|
||||
|
||||
The action generates a structured code review that includes:
|
||||
|
||||
- **Strengths**: What was done well in the PR
|
||||
- **Issues Found**: Categorized by severity (Critical, High, Medium, Low)
|
||||
- **Suggestions**: Improvement recommendations
|
||||
- **Overall Assessment**: Final recommendation (APPROVE, REQUEST_CHANGES, or COMMENT)
|
||||
|
||||
## Troubleshooting
|
||||
|
||||
### Review not triggering
|
||||
- Ensure the PR author or commenter has appropriate permissions (OWNER, MEMBER, or COLLABORATOR)
|
||||
- Check that the workflow file is in the default branch
|
||||
- Verify the Continue API key is correctly set as a repository secret
|
||||
|
||||
### No review output generated
|
||||
- Check the action logs for any errors
|
||||
- Verify your Continue configuration is correct
|
||||
- Ensure your Continue API key is valid
|
||||
|
||||
## Support
|
||||
|
||||
For issues or questions:
|
||||
- [Continue Documentation](https://docs.continue.dev)
|
||||
- [GitHub Issues](https://github.com/continuedev/continue/issues)
|
||||
- [Discord Community](https://discord.gg/vapESyrFmJ)
|
||||
204
pr-review-action/action.yml
Normal file
204
pr-review-action/action.yml
Normal file
|
|
@ -0,0 +1,204 @@
|
|||
name: 'Continue PR Review'
|
||||
description: 'Automated 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: Check Authorization
|
||||
shell: bash
|
||||
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 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
|
||||
elif [ "${{ github.event_name }}" = "issue_comment" ]; then
|
||||
# Check if it's a PR comment with the trigger phrase
|
||||
if [ "${{ github.event.issue.pull_request }}" != "" ] && [[ "${{ github.event.comment.body }}" == *"@continue-review"* ]]; 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-review trigger or is not on a PR"
|
||||
fi
|
||||
else
|
||||
echo "::notice::Skipping review - Unsupported event type: ${{ github.event_name }}"
|
||||
fi
|
||||
|
||||
echo "SHOULD_RUN=$SHOULD_RUN" >> $GITHUB_ENV
|
||||
|
||||
- name: Setup Node.js
|
||||
if: env.SHOULD_RUN == 'true'
|
||||
uses: actions/setup-node@v4
|
||||
with:
|
||||
node-version: 20
|
||||
|
||||
- name: Install Continue CLI
|
||||
if: env.SHOULD_RUN == 'true'
|
||||
shell: bash
|
||||
run: npm install -g @continuedev/cli@1.4.25
|
||||
|
||||
- name: Build PR Review Prompt
|
||||
if: env.SHOULD_RUN == 'true'
|
||||
shell: bash
|
||||
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 diff
|
||||
gh pr diff $PR_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'
|
||||
|
||||
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.
|
||||
EOF
|
||||
|
||||
- name: Run Continue CLI Review
|
||||
if: env.SHOULD_RUN == 'true'
|
||||
shell: bash
|
||||
run: |
|
||||
echo "Running Continue CLI with prompt:"
|
||||
echo "=================================="
|
||||
cat review_prompt.txt
|
||||
echo "=================================="
|
||||
echo ""
|
||||
|
||||
# Run the CLI with provided config
|
||||
cat review_prompt.txt | cn --readonly --org ${{ inputs.continue-org }} --config ${{ inputs.continue-config }} -p > code_review.md
|
||||
env:
|
||||
CONTINUE_API_KEY: ${{ inputs.continue-api-key }}
|
||||
|
||||
- name: Upload Review Results
|
||||
if: env.SHOULD_RUN == 'true' && always()
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: code-review-results
|
||||
path: |
|
||||
code_review.md
|
||||
review_prompt.txt
|
||||
pr_diff.txt
|
||||
retention-days: 30
|
||||
|
||||
- name: Comment PR with Review
|
||||
if: env.SHOULD_RUN == 'true' && always()
|
||||
uses: actions/github-script@v7
|
||||
with:
|
||||
script: |
|
||||
const fs = require('fs');
|
||||
|
||||
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.';
|
||||
}
|
||||
|
||||
// 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;
|
||||
}
|
||||
|
||||
// Add a header if triggered by comment
|
||||
if (context.eventName === 'issue_comment') {
|
||||
reviewContent = `*Triggered by @${context.payload.comment.user.login}'s request*\n\n${reviewContent}`;
|
||||
}
|
||||
|
||||
// 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}`);
|
||||
} catch (error) {
|
||||
console.log('Failed to post comment:', error.message);
|
||||
console.log('Error details:', error);
|
||||
}
|
||||
|
||||
branding:
|
||||
icon: 'code'
|
||||
color: 'blue'
|
||||
Loading…
Add table
Reference in a new issue