import { Command } from 'commander'; import { BaseCommand } from './BaseCommand'; import { ReviewCodeUseCaseImpl } from '../../domain/usecases/ReviewCodeUseCase'; export class ReviewCommand extends BaseCommand { constructor() { super('review', 'Review code changes and provide AI-powered feedback'); this.option('--post-to-github', 'Post review comments to GitHub PR') .option('--github-owner ', 'GitHub repository owner') .option('--github-repo ', 'GitHub repository name') .option('--pull-request ', 'GitHub pull request number') .option('--severity ', 'Review severity levels (info,warning,error,suggestion)') .option('--categories ', 'Review categories (style,logic,security,performance,maintainability,documentation,testing,accessibility)') .option('--include-metadata', 'Include metadata in output'); } protected async execute(options: any, command: Command): Promise { const useCase = new ReviewCodeUseCaseImpl( this.gitAdapter, this.llmAdapter, this.outputAdapter ); const reviewOptions: any = { baseRef: options.baseRef, headRef: options.headRef, includeStaged: options.staged, includeUnstaged: options.unstaged, filePatterns: this.parseFilePatterns(options.filePatterns) || [], excludePatterns: this.parseExcludePatterns(options.excludePatterns) || [], outputFormat: this.getOutputFormat(options) as 'html' | 'json' | 'markdown' | 'console' | 'file' | 'github', postToGitHub: options.postToGithub, githubOwner: options.githubOwner, githubRepo: options.githubRepo, pullRequestNumber: options.pullRequest ? parseInt(options.pullRequest) : undefined, }; const outputPath = this.getOutputPath(options); if (outputPath) { reviewOptions.outputPath = outputPath; } if (this.isVerbose(options)) { console.log('Starting code review...'); console.log('Options:', reviewOptions); } try { const report = await useCase.execute(reviewOptions); if (this.isVerbose(options)) { console.log(`Review completed. Found ${report.comments.length} comments.`); } } catch (error) { throw new Error(`Review failed: ${error instanceof Error ? error.message : 'Unknown error'}`); } } }