review-copilot
Version:
ReviewCopilot - AI-powered code review assistant with customizable prompts
108 lines (101 loc) • 3.53 kB
JavaScript
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.initCommand = initCommand;
const promises_1 = require("fs/promises");
const fs_1 = require("fs");
const path_1 = __importDefault(require("path"));
const chalk_1 = __importDefault(require("chalk"));
const ora_1 = __importDefault(require("ora"));
const defaultConfig = `
providers:
openai:
enabled: false
apiKey: \${AI_API_KEY_OPENAI}
model: gpt-4o-mini
baseURL: https://api.openai.com/v1
reviewLanguage: 'zh'
deepseek:
enabled: true
apiKey: \${AI_API_KEY_DEEPSEEK}
model: deepseek-chat
baseURL: https://api.deepseek.com/v1
reviewLanguage: 'zh'
triggers:
- on: pull_request
- on: merge_request
- on: push
rules:
commitMessage:
enabled: true
pattern: '^(feat|fix|docs|style|refactor|test|chore|ci)(\\(.+\\))?: .{1,50}'
prompt: |
Review this commit message and ensure it follows conventional commits format.
Format: <type>(<scope>): <description>
Types: feat, fix, docs, style, refactor, test, chore, ci
branchName:
enabled: true
pattern: '^(feature|bugfix|hotfix|release)/[A-Z]+-[0-9]+-.+'
prompt: |
Verify branch name follows the pattern:
<type>/<ticket-id>-<description>
Types: feature, bugfix, hotfix, release
codeChanges:
enabled: true
filePatterns:
- '**/*.{ts,tsx}'
- '**/*.{js,jsx}'
- '**/*.{json}'
- '**/*.{yaml}'
- '**/*.{yml}'
- '!package-lock.json'
- '!**/package-lock.json'
- '!yarn.lock'
- '!**/yarn.lock'
- '!pnpm-lock.yaml'
- '!**/pnpm-lock.yaml'
- '!**/dist/**'
- '!**/node_modules/**'
- '!**/*.min.js'
- '!**/*.bundle.js'
prompt: |
Review the code changes for:
1. Code style and formatting
2. Potential bugs and issues
3. Performance considerations
4. Security vulnerabilities
5. Best practices compliance
customReviewPoints:
- name: 'Security Check'
prompt: 'Review code for security vulnerabilities...'
- name: 'Performance Review'
prompt: 'Analyze code for performance bottlenecks...'
`;
async function initCommand() {
const spinner = (0, ora_1.default)('Initializing ReviewCopilot configuration...').start();
try {
const configPath = path_1.default.join(process.cwd(), '.review-copilot.yaml');
if ((0, fs_1.existsSync)(configPath)) {
spinner.succeed(chalk_1.default.blue('Using existing configuration file'));
return;
}
await (0, promises_1.writeFile)(configPath, defaultConfig, 'utf8');
spinner.succeed(chalk_1.default.green('Configuration file created successfully!'));
console.log('\nNext steps:');
console.log(chalk_1.default.blue('1. Set your OpenAI API key in .env or as environment variable'));
console.log(chalk_1.default.blue('2. Customize the configuration in .review-copilot.yaml'));
console.log(chalk_1.default.blue('3. Run `review-copilot review` to start reviewing code\n'));
}
catch (error) {
spinner.fail(chalk_1.default.red('Failed to create configuration file'));
console.error(error);
throw new Error('process.exit');
}
}