@dharshansr/gitgenius
Version:
AI-powered commit message generator with enhanced features
106 lines • 5.16 kB
JavaScript
import chalk from 'chalk';
import ora from 'ora';
import { GitService } from '../services/GitService.js';
import { AIService } from '../services/AIService.js';
import { ConfigManager } from '../core/ConfigManager.js';
export class SystemOperations {
constructor() {
this.gitService = new GitService();
this.aiService = new AIService();
this.configManager = new ConfigManager();
}
async showStats(options) {
try {
const days = parseInt(options.days || '30');
const since = new Date();
since.setDate(since.getDate() - days);
const logs = await this.gitService.getLog({
from: since.toISOString(),
...(options.author && { author: options.author })
});
const stats = this.gitService.calculateStats(logs);
this.gitService.displayStats(stats, days, options.author);
}
catch (error) {
throw new Error(`Failed to generate stats: ${error instanceof Error ? error.message : String(error)}`);
}
}
async checkUpdates(options) {
try {
console.log(chalk.blue('[UPDATE] Checking for GitGenius updates...'));
const currentVersion = '1.0.0';
// In real implementation, would check npm registry
const spinner = ora('Checking npm registry...').start();
setTimeout(async () => {
spinner.stop();
// Simulate update check
const latestVersion = '1.0.0'; // Would fetch from npm
if (currentVersion === latestVersion) {
console.log(chalk.green(`✨ [SUCCESS] GitGenius is up to date (v${currentVersion})`));
}
else {
console.log(chalk.yellow(`[UPDATE] Update available: v${currentVersion} → v${latestVersion}`));
console.log(chalk.blue('[INFO] Run: npm install -g gitgenius@latest'));
if (options.force) {
console.log(chalk.yellow('[UPDATE] Force update requested...'));
console.log(chalk.green('✨ [SUCCESS] GitGenius updated successfully!'));
}
}
// Show changelog
console.log(chalk.blue('\n[CHANGELOG] Recent changes:'));
console.log(chalk.white('• Enhanced AI commit message generation'));
console.log(chalk.white('• Added branch management features'));
console.log(chalk.white('• Improved error handling'));
}, 1000);
}
catch (error) {
throw new Error(`Failed to check updates: ${error instanceof Error ? error.message : String(error)}`);
}
}
async showWhoami() {
try {
console.log(chalk.blue('[IDENTITY] GitGenius Identity:'));
const provider = process.env.GITGENIUS_PROVIDER || this.configManager.getConfig('provider') || 'openai';
const model = process.env.GITGENIUS_MODEL || this.configManager.getConfig('model') || 'gpt-3.5-turbo';
console.log(chalk.white(`Provider: ${chalk.yellow(provider)}`));
console.log(chalk.white(`Model: ${chalk.yellow(model)}`));
if (this.configManager.hasApiKey()) {
const apiKey = this.configManager.getApiKey();
const maskedKey = apiKey ? `${apiKey.substring(0, 8)}...${apiKey.substring(apiKey.length - 4)}` : 'Not set';
console.log(chalk.white(`API Key: ${chalk.green(maskedKey)}`));
console.log(chalk.green('✨ [SUCCESS] Ready to generate commit messages'));
}
else {
console.log(chalk.red('[ERROR] No API key configured'));
console.log(chalk.yellow('[INFO] Run: gitgenius config apiKey'));
}
// Show git user info
try {
const userName = await this.gitService.getConfig('user.name');
const userEmail = await this.gitService.getConfig('user.email');
console.log(chalk.white(`Git User: ${chalk.cyan(`${userName.value} <${userEmail.value}>`)}`));
}
catch {
console.log(chalk.yellow('[WARNING] Git user not configured'));
}
// Show repository info
try {
const isRepo = await this.gitService.checkIsRepo();
if (isRepo) {
const branch = await this.gitService.getBranchLocal();
console.log(chalk.white(`Current Branch: ${chalk.cyan(branch.current)}`));
}
else {
console.log(chalk.yellow('[WARNING] Not in a git repository'));
}
}
catch {
console.log(chalk.yellow('[WARNING] Unable to read git repository'));
}
}
catch (error) {
throw new Error(`Failed to show identity: ${error instanceof Error ? error.message : String(error)}`);
}
}
}
//# sourceMappingURL=SystemOperations.js.map