Getting Started Guide
You:
Based upon our current implementation, what would the getting started look like for a team or a user that wants to take advantage of the AIPR ReviewBot?
ChatGPT:
"Getting started with the AIPR ReviewBot should feel like onboarding your new best team member. Let’s make it as smooth and straightforward as possible for any team or user to integrate, configure, and leverage the bot for their code reviews."
Getting Started Guide for AIPR ReviewBot
Step 1: Prerequisites
Before diving in, ensure you have the following ready:
- GitHub Repository: A repository where you want the bot to work.
- Admin Access: Permissions to configure GitHub Actions and repository secrets.
- OpenAI API Key: Access to OpenAI services (for generating AI-powered reviews).
- Node.js Environment: Required for local testing or extending the bot.
Step 2: Add the Bot to Your Repository
1. Install the GitHub Action
-
Add the AIPR ReviewBot GitHub Action to your repository.
-
Example
.github/workflows/aipr-review.yml:name: AI-Powered PR Review
on:
pull_request:
types: [opened, synchronize]
jobs:
review:
runs-on: ubuntu-latest
steps:
# Step 1: Check out the repository
- name: Checkout code
uses: actions/checkout@v3
# Step 2: Set up Node.js
- name: Set up Node.js
uses: actions/setup-node@v3
with:
node-version: '16'
# Step 3: Install dependencies
- name: Install dependencies
run: npm install
# Step 4: Run AIPR ReviewBot
- name: Run AIPR ReviewBot
uses: ./actions/ai-pr-review
with:
repo_owner: ${{ github.repository_owner }}
repo_name: ${{ github.event.repository.name }}
pr_number: ${{ github.event.pull_request.number }}
env:
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
2. Configure Repository Secrets
Add the required API keys and tokens:
- GitHub Token: Automatically available as
GITHUB_TOKEN. - OpenAI API Key:
- Go to Settings → Secrets and Variables → Actions.
- Add a new secret:
- Name:
OPENAI_API_KEY - Value: Your OpenAI API key.
- Name:
Step 3: Add a Configuration File
1. Create a Configuration File
Add a bot-config.json file to your repository at .github/bot-config.json.
Example:
{
"general": {
"enableSuggestions": true,
"enableEvaluations": true,
"defaultRiskThreshold": 7,
"enableAutoComments": true
},
"evaluations": {
"codeComplexity": {
"maxCyclomaticComplexity": 10
},
"testCoverage": {
"minTestCoverage": 80
},
"securityChecks": {
"enableSecurityChecks": true
}
},
"suggestions": {
"enableSuggestions": true,
"suggestionTypes": ["refactor", "tests", "linting"]
},
"persona": {
"name": "CodeGuard",
"tone": "friendly",
"commentTemplates": {
"complexity": "This function exceeds the allowed cyclomatic complexity. Consider refactoring.",
"coverage": "This file does not meet the required test coverage of {minTestCoverage}%. Please add more tests."
}
}
}
2. Customize Configurations
- Enable or Disable Features:
- Turn on/off code suggestions, evaluations, or specific checks (e.g., security or test coverage).
- Set Risk Thresholds:
- Define what constitutes "high-risk" for your team.
- Customize Persona:
- Adjust the bot’s tone and comment templates to fit your team's culture.
Step 4: Trigger Your First Review
1. Create a Pull Request
- Open a PR in your repository.
- The bot will:
- Analyze diffs.
- Provide feedback as comments.
- Suggest code changes (if enabled).
2. Review Bot Comments
Example Output:
### 🛠 AI-Powered Review by CodeGuard
**File:** `src/app/file.ts`
**Lines:** 10-20
The changes in this block introduce high cyclomatic complexity. Consider refactoring the logic to improve readability and maintainability.
**Risk Score:** 8/10
**Recommendations:**
- Refactor the `calculate()` function to reduce nested conditionals.
- Add unit tests for edge cases.
3. Apply Suggestions
- For code suggestions, click "Apply Suggestion" directly in the PR comment to commit the change.
Step 5: Monitor and Improve
1. Fine-Tune Configurations
- As your team uses the bot, adjust the
bot-config.jsonfile to improve feedback relevance:- Change thresholds (e.g., complexity or coverage).
- Add new evaluation criteria or comment templates.
2. Analyze Risk Trends
- Use the bot’s risk scoring to identify patterns:
- Frequently flagged files or modules.
- Repeated coding issues (e.g., missing tests or complexity creep).
Step 6: Extend the Bot (Optional)
1. Add New Features
- Add custom evaluation logic:
- Example: Linting checks, security scans, or performance analysis.
- Modify the
ai-pr-reviewaction’s code to include these checks.
2. Local Testing
Run the bot locally for testing:
node index.js --repo your-org/your-repo --pr 123
3. Integrate with Other Tools
- Connect the bot to Slack or email notifications to alert team members about high-risk PRs.
Best Practices for Teams
-
Start Small:
- Use default settings to get initial feedback.
- Gradually enable more advanced features like suggestions and scoring.
-
Involve the Team:
- Share the bot’s feedback in team reviews to refine its behavior.
- Encourage developers to customize the configuration for their needs.
-
Iterate and Improve:
- Regularly update the configuration file based on team feedback.
- Use the bot’s insights to improve coding standards and reduce risks.
Summary Workflow
- Install the bot as a GitHub Action.
- Set up repository secrets for the OpenAI API key.
- Add and customize the
bot-config.jsonfile. - Create a PR to trigger the bot.
- Review and apply suggestions.
- Monitor and iterate on configurations for continuous improvement.
Let me know if you'd like any of these steps expanded, or if we should dive into specific examples or customizations! 🚀