From 75ddb76ddd774dd843428a7084999dd3ab3efee7 Mon Sep 17 00:00:00 2001 From: Mike Date: Fri, 17 Feb 2023 20:12:45 -0600 Subject: [PATCH 1/2] Feature: :sparkles: Add Gitmoji option --- src/cli.ts | 7 +++++++ src/utils.ts | 5 +++-- 2 files changed, 10 insertions(+), 2 deletions(-) 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..66d1adec 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, the response must be in the lang' }:\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) { From c5163355f1510f48e2fd31cd29aaa0c0bf420603 Mon Sep 17 00:00:00 2001 From: Th3Kr4t3 <31254901+Th3Kr4t3@users.noreply.github.com> Date: Fri, 17 Feb 2023 21:10:36 -0600 Subject: [PATCH 2/2] Remove test code --- src/utils.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/utils.ts b/src/utils.ts index 66d1adec..6108c6f5 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -62,7 +62,7 @@ export const getDetectedMessage = (files: string[]) => `Detected ${files.length. const sanitizeMessage = (message: string) => message.trim().replace(/[\n\r]/g, '').replace(/(\w)\.$/, '$1'); -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, the response must be in the lang' }:\n${diff}`; +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,