UNPKG

review-copilot

Version:

ReviewCopilot - AI-powered code review assistant with customizable prompts

95 lines (94 loc) 3.75 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.LocalGitService = void 0; const child_process_1 = require("child_process"); const fs_1 = __importDefault(require("fs")); class LocalGitService { async getPRDetails() { // In local development, we'll use the current branch and repository info try { const remoteUrl = (0, child_process_1.execSync)('git config --get remote.origin.url') .toString() .trim(); const branch = (0, child_process_1.execSync)('git rev-parse --abbrev-ref HEAD') .toString() .trim(); // Parse remote URL to get owner and repo // Handle both HTTPS and SSH URLs let owner, repo; if (remoteUrl.startsWith('https://')) { const parts = remoteUrl.replace('https://', '').split('/'); owner = parts[parts.length - 2]; repo = parts[parts.length - 1].replace('.git', ''); } else { // SSH URL format: git@github.com:owner/repo.git const parts = remoteUrl.split(':')[1].split('/'); owner = parts[0]; repo = parts[1].replace('.git', ''); } // For local development, we'll use a dummy PR number return { owner, repo, pullNumber: 1, // Dummy PR number for local development platform: 'github', // Default to GitHub for local development commitId: '', path: '', }; } catch (error) { console.error('Error getting local git details:', error); return undefined; } } async createIssueComment({ owner, repo, issue_number, body, }) { // In local development, just log the comment console.log('\n=== Review Comment ==='); console.log(body); console.log('=====================\n'); } async createReviewComment(params) { // In local development, just log the comment console.log('\n=== Review Comment ==='); console.log(params.body); console.log('=====================\n'); } async replyToComment(params) { // In local development, just log the reply console.log('\n=== Reply to Comment ==='); console.log(`Comment ID: ${params.commentId}`); console.log(params.comment); console.log('=====================\n'); } async replyToReviewComment(params) { // In local development, just log the review reply console.log('\n=== Reply to Review Comment ==='); console.log(`Thread ID: ${params.threadId}`); console.log(params.comment); console.log('=====================\n'); } async getCurrentBranch() { return (0, child_process_1.execSync)('git rev-parse --abbrev-ref HEAD').toString().trim(); } async getCommitMessage() { return (0, child_process_1.execSync)('git log -1 --pretty=%B').toString().trim(); } async getFileContent(params) { try { // In local development, read the file directly from the filesystem if (fs_1.default.existsSync(params.filePath)) { return fs_1.default.readFileSync(params.filePath, 'utf8'); } return null; } catch (error) { console.error('Error reading file:', error); return null; } } } exports.LocalGitService = LocalGitService;