UNPKG

refakts

Version:

TypeScript refactoring tool built for AI coding agents to perform precise refactoring operations via command line instead of requiring complete code regeneration.

53 lines 1.92 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.checkGitDiffSize = checkGitDiffSize; const child_process_1 = require("child_process"); const util_1 = require("util"); const execAsync = (0, util_1.promisify)(child_process_1.exec); async function checkGitDiffSize() { try { const { stdout } = await execAsync('git diff --numstat'); return processDiffOutput(stdout); } catch (error) { return { lines: 0, severity: 'ok' }; } } function processDiffOutput(stdout) { if (!stdout.trim()) { return { lines: 0, severity: 'ok' }; } const totalChanges = calculateTotalChanges(stdout); return createDiffSizeResult(totalChanges); } function calculateTotalChanges(stdout) { const lines = stdout.trim().split('\n'); return lines.reduce((sum, line) => { const [added, deleted] = line.split('\t').map(Number); return sum + (added || 0) + (deleted || 0); }, 0); } function createDiffSizeResult(totalChanges) { if (totalChanges > 200) { return createCriticalDiffResult(totalChanges); } else if (totalChanges > 100) { return createWarningDiffResult(totalChanges); } return { lines: totalChanges, severity: 'ok' }; } function createCriticalDiffResult(totalChanges) { return { lines: totalChanges, severity: 'critical', message: '👧🏻💬 STOP! Your diff is over 200 lines. This is too much change at once. Revert to last commit and break this into smaller steps with passing tests between each step.' }; } function createWarningDiffResult(totalChanges) { return { lines: totalChanges, severity: 'warn', message: '👧🏻💬 Your diff is getting large (100+ lines). Consider committing smaller incremental changes with passing tests to maintain code quality.' }; } //# sourceMappingURL=git-diff-checker.js.map