Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: ✨ Add Gitmoji option #76

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down Expand Up @@ -63,6 +69,7 @@ const argv = cli({
OPENAI_KEY,
staged.diff,
argv.flags.generate,
argv.flags.gitmoji,
);
s.stop('Changes analyzed');

Expand Down
5 changes: 3 additions & 2 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down