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

Allow for commit prefix #160

Open
wants to merge 16 commits into
base: dev
Choose a base branch
from
Open
Changes from 1 commit
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
Next Next commit
feat(api.ts): add support for prefix configuration to be added to the…
… generated message

feat(config.ts): add prefix configuration option to be used in the generated message. Add validation to ensure prefix is not empty.
  • Loading branch information
amitayk committed May 4, 2023
commit 83a919b0fb3689301d5689f82f18d97bb87b8655
14 changes: 13 additions & 1 deletion src/api.ts
Original file line number Diff line number Diff line change
@@ -59,7 +59,11 @@ class OpenAi {

const message = data.choices[0].message;

return message?.content;
const prefix = generatePrefix();

const finalMessage = (prefix || '') + (message?.content || '');

return finalMessage;
} catch (error: unknown) {
outro(`${chalk.red('✖')} ${error}`);

@@ -94,4 +98,12 @@ export const getOpenCommitLatestVersion = async (): Promise<
}
};

function generatePrefix(): string | undefined {
if (!config?.prefix) {
return undefined;
}
return config.prefix;
}

export const api = new OpenAi();

13 changes: 12 additions & 1 deletion src/commands/config.ts
Original file line number Diff line number Diff line change
@@ -15,7 +15,8 @@ export enum CONFIG_KEYS {
description = 'description',
emoji = 'emoji',
model = 'model',
language = 'language'
language = 'language',
prefix = 'prefix'
}

export enum CONFIG_MODES {
@@ -109,7 +110,17 @@ export const configValidators = {
`${value} is not supported yet, use 'gpt-4' or 'gpt-3.5-turbo' (default)`
);
return value;
},

[CONFIG_KEYS.prefix](value: any) {
validateConfig(
CONFIG_KEYS.prefix,
value,
'Cannot be empty'
);
return value;
}

};

export type ConfigType = {