UNPKG

@marsdevs-com/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.

69 lines (65 loc) 2.76 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.AISummarizer = void 0; const sdk_1 = __importDefault(require("@anthropic-ai/sdk")); class AISummarizer { constructor(apiKey) { this.anthropic = new sdk_1.default({ apiKey: apiKey, }); } /** * Generate a summary of changes from commit messages using Anthropic API */ async generateSummary(commitMessages, totalLinesChanged) { try { const prompt = this.buildPrompt(commitMessages, totalLinesChanged); const response = await this.anthropic.messages.create({ model: 'claude-3-haiku-20240307', max_tokens: 500, messages: [ { role: 'user', content: prompt } ] }); return response.content[0].type === 'text' ? response.content[0].text : 'Unable to generate summary'; } catch (error) { console.warn(`Failed to generate AI summary: ${error instanceof Error ? error.message : 'Unknown error'}`); return this.generateFallbackSummary(commitMessages, totalLinesChanged); } } /** * Build the prompt for the AI model */ buildPrompt(commitMessages, totalLinesChanged) { const messagesText = commitMessages.join('\n'); return `You are a helpful assistant that summarizes daily development work based on commit messages. Given the following commit messages from a single day of development work, provide a concise, simple summary of what was accomplished. Focus on the main changes and improvements made. Commit messages: ${messagesText} Total lines of code changed: ${totalLinesChanged} Please provide a brief, clear summary in simple language that describes what work was done that day. Keep it under 3 sentences and focus on the most important changes.`; } /** * Generate a fallback summary when AI is not available */ generateFallbackSummary(commitMessages, totalLinesChanged) { const uniqueMessages = [...new Set(commitMessages)]; const messageCount = uniqueMessages.length; if (messageCount === 0) { return 'No changes were made on this date.'; } if (messageCount === 1) { return `Made changes: ${uniqueMessages[0]}`; } return `Completed ${messageCount} tasks with ${totalLinesChanged} lines of code changed.`; } } exports.AISummarizer = AISummarizer; //# sourceMappingURL=ai-summarizer.js.map