UNPKG

smart-git-commit

Version:

AI-powered smart commit message generator for Git diffs.

38 lines (29 loc) 1.24 kB
export default function buildPrompt(fileChanges) { let prompt = "You are a helpful AI that writes conventional git commit messages.\n\n"; prompt += "Based on the following code changes, suggest a concise, single-line commit message following the Conventional Commits format:\n"; prompt += "Format: <type>(<scope>): <short description>\n"; prompt += "Where <type> is one of: feat, fix, chore, refactor, docs, test, ci, build\n\n"; const maxFiles = 10; const maxLinesPerFile = 2; fileChanges.slice(0, maxFiles).forEach((file) => { prompt += `File: ${file.file} | Change: ${file.changeType}\n`; const sampleAdditions = file.additions.slice(0, maxLinesPerFile); const sampleDeletions = file.deletions.slice(0, maxLinesPerFile); if (sampleAdditions.length > 0) { prompt += `+ ${sampleAdditions.join("\n+ ")}\n`; } if (sampleDeletions.length > 0) { prompt += `- ${sampleDeletions.join("\n- ")}\n`; } prompt += "\n"; }); if (fileChanges.length > maxFiles) { prompt += `...and ${fileChanges.length - maxFiles} more files changed.\n`; } prompt += "\nRespond ONLY with the commit message in the correct Conventional Commits format."; return prompt; }