diff --git a/src/cli.ts b/src/cli.ts index 5b3f4265..076de92d 100644 --- a/src/cli.ts +++ b/src/cli.ts @@ -27,6 +27,12 @@ const argv = cli({ alias: 'g', default: 1, }, + gitmoji: { + type: Boolean, + description: 'Toggle whether to use a Gitmoji or not', + alias: 'j', + default: false, + } }, help: { @@ -63,6 +69,7 @@ const argv = cli({ OPENAI_KEY, staged.diff, argv.flags.generate, + argv.flags.gitmoji, ); s.stop('Changes analyzed'); diff --git a/src/utils.ts b/src/utils.ts index e5cefff5..6108c6f5 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -62,14 +62,15 @@ export const getDetectedMessage = (files: string[]) => `Detected ${files.length. const sanitizeMessage = (message: string) => message.trim().replace(/[\n\r]/g, '').replace(/(\w)\.$/, '$1'); -const promptTemplate = 'Write an insightful but concise Git commit message in a complete sentence in present tense for the following diff without prefacing it with anything:'; +const getPrompt = (gitmoji: boolean, diff: string) => `Write an insightful but concise Git commit message in a complete sentence in present tense for the following diff ${gitmoji ? 'preface with the suitable Gitmoji markup between colons:' : 'without prefacing it with anything:' }:\n${diff}`; export const generateCommitMessage = async ( apiKey: string, diff: string, completions: number, + gitmoji: boolean, ) => { - const prompt = `${promptTemplate}\n${diff}`; + const prompt = getPrompt(gitmoji, diff); // Accounting for GPT-3's input req of 4k tokens (approx 8k chars) if (prompt.length > 8000) {