commit-guardian
Version:
Interactive CLI tool with browser-based GitHub-style diff viewer for reviewing and approving git changes before commit. Features React-based UI, approval workflow, line comments, and safe commit protection.
66 lines (65 loc) ⢠2.56 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const express_1 = __importDefault(require("express"));
const router = express_1.default.Router();
router.post('/reject', async (req, res) => {
try {
const { rejectReason, fileComments } = req.body;
console.log('\nā Changes rejected');
if (rejectReason) {
console.log('\nš Rejection reason:');
console.log('='.repeat(50));
console.log(rejectReason);
console.log('');
}
if (fileComments && fileComments.length > 0) {
console.log('\nš Review comments for LLM analysis:');
console.log('='.repeat(50));
fileComments.forEach((comment, index) => {
console.log(`${index + 1}. File: ${comment.file}:${comment.line}`);
console.log(` Comment: ${comment.text}`);
console.log('');
});
console.log('\nš¤ LLM Analysis Format:');
console.log('='.repeat(30));
if (rejectReason) {
console.log(`Reject Reason: ${rejectReason}`);
}
fileComments.forEach(comment => {
console.log(`${comment.file}:${comment.line} - ${comment.text}`);
});
}
else {
console.log('ā¹ļø No comments provided');
}
console.log('\nš Note: After making the requested changes, you need to stage the modified files again:');
console.log(' Use: git add <filename>');
console.log(' Example: git add src/component.js');
console.log('');
// Call the approval callback if provided
const options = global.commitGuardianOptions;
if (options?.onApproval) {
options.onApproval(false, undefined, rejectReason, fileComments);
}
const response = {
success: true
};
res.json(response);
// Shutdown server after rejection
setTimeout(() => {
console.log('šŖ Shutting down server after rejection...');
process.exit(0);
}, 1000);
}
catch (error) {
console.error('Error handling rejection:', error);
res.status(500).json({
success: false,
error: error instanceof Error ? error.message : 'Rejection failed'
});
}
});
exports.default = router;