UNPKG

review-copilot

Version:

ReviewCopilot - AI-powered code review assistant with customizable prompts

56 lines (55 loc) 2.1 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.getGitChanges = getGitChanges; exports.getCurrentBranchName = getCurrentBranchName; exports.getCurrentCommitMessage = getCurrentCommitMessage; const simple_git_1 = __importDefault(require("simple-git")); const chalk_1 = __importDefault(require("chalk")); async function getGitChanges() { const git = (0, simple_git_1.default)(); const status = await git.status(); const changes = []; for (const file of [...status.modified, ...status.not_added]) { const diff = await git.diff([file]); changes.push({ file, content: diff }); } return changes; } async function getCurrentBranchName() { try { const git = (0, simple_git_1.default)(); const branch = await git.branch(); if (!branch.current) { console.warn(chalk_1.default.yellow('Warning: Could not determine current branch name')); return ''; } console.log(chalk_1.default.blue('Current branch:'), chalk_1.default.green(branch.current)); return branch.current; } catch (error) { console.error(chalk_1.default.red('Error getting branch name:'), error); throw new Error(`Failed to get branch name: ${error}`); } } async function getCurrentCommitMessage() { try { const git = (0, simple_git_1.default)(); const log = await git.log({ maxCount: 1 }); if (!log.latest?.message) { console.warn(chalk_1.default.yellow('Warning: No commit message found')); return ''; } console.log(chalk_1.default.blue('Current commit message:'), chalk_1.default.green(log.latest.message)); return log.latest.message; } catch (error) { console.error(chalk_1.default.red('Error getting commit message:'), error); throw new Error(`Failed to get commit message: ${error}`); } }