UNPKG

git-workreport

Version:

A powerful GitHub plugin that generates AI-powered work reports from Git commit history for specified dates. Perfect for DevOps teams and development companies to track and validate work progress with intelligent summaries.

95 lines • 4.46 kB
#!/usr/bin/env node "use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const commander_1 = require("commander"); const chalk_1 = __importDefault(require("chalk")); const ora_1 = __importDefault(require("ora")); const moment_1 = __importDefault(require("moment")); const git_analyzer_1 = require("./git-analyzer"); const report_generator_1 = require("./report-generator"); const program = new commander_1.Command(); program .name('git-workreport') .description('Generate work reports from Git commit history for specified dates') .version('1.0.0') .argument('[date]', 'Date in DD/MM/YYYY format (defaults to today)') .option('-f, --format <format>', 'Output format: text, json, or markdown', 'text') .option('-o, --output <file>', 'Output file path') .option('--no-stats', 'Exclude statistics from the report') .option('--no-files', 'Exclude file lists from the report') .option('--timezone <tz>', 'Timezone for date parsing', 'local') .option('--repo <path>', 'Path to Git repository (defaults to current directory)') .option('--anthropic-key <key>', 'Anthropic API key for AI-generated summaries') .parse(); async function main() { try { const args = program.args; const options = program.opts(); // Get date argument or default to today let date = args[0]; if (!date) { date = (0, moment_1.default)().format('DD/MM/YYYY'); console.log(chalk_1.default.blue(`No date specified, using today: ${date}`)); } // Validate date format const parsedDate = (0, moment_1.default)(date, ['DD/MM/YYYY', 'YYYY-MM-DD', 'MM/DD/YYYY']); if (!parsedDate.isValid()) { console.error(chalk_1.default.red(`Error: Invalid date format "${date}". Please use DD/MM/YYYY format.`)); process.exit(1); } // Create options object const reportOptions = { date, format: options.format, output: options.output, includeStats: options.stats !== false, includeFiles: options.files !== false, timezone: options.timezone, anthropicApiKey: options.anthropicKey }; // Initialize components const analyzer = new git_analyzer_1.GitAnalyzer(options.repo); const generator = new report_generator_1.ReportGenerator(); // Show loading spinner const spinner = (0, ora_1.default)('Analyzing Git repository...').start(); // Generate work report const report = await analyzer.generateWorkReport(date, reportOptions); spinner.succeed('Analysis complete!'); // Generate formatted report const formattedReport = generator.generateReport(report, reportOptions); // Output or save report if (options.output) { const outputPath = generator.saveReport(formattedReport, options.output, options.format); console.log(chalk_1.default.green(`\nReport saved to: ${outputPath}`)); } else { console.log('\n' + formattedReport); } // Show summary console.log(chalk_1.default.cyan('\nšŸ“Š Report Summary:')); console.log(chalk_1.default.cyan(` Date: ${report.date}`)); console.log(chalk_1.default.cyan(` Commits: ${report.totalCommits}`)); console.log(chalk_1.default.cyan(` Authors: ${report.authors.length}`)); console.log(chalk_1.default.cyan(` Total Lines Changed: ${report.totalLinesChanged}`)); } catch (error) { console.error(chalk_1.default.red('\nāŒ Error:'), error instanceof Error ? error.message : 'Unknown error occurred'); if (error instanceof Error && error.message.includes('not a git repository')) { console.log(chalk_1.default.yellow('\nšŸ’” Make sure you are in a Git repository or specify the repository path with --repo option.')); } process.exit(1); } } // Handle unhandled promise rejections process.on('unhandledRejection', (reason, promise) => { console.error(chalk_1.default.red('\nāŒ Unhandled Rejection at:'), promise, chalk_1.default.red('reason:'), reason); process.exit(1); }); // Run the CLI if (require.main === module) { main(); } //# sourceMappingURL=cli.js.map