diff --git a/README.md b/README.md index 1b27b530..75229744 100644 --- a/README.md +++ b/README.md @@ -98,6 +98,12 @@ This flag allows users to automatically commit the changes without having to man oco --yes ``` +You can also set this behavior permanently through configuration: + +``` +oco config set OCO_SKIP_COMMIT_CONFIRM=true +``` + ## Configuration ### Local per repo configuration @@ -119,6 +125,7 @@ OCO_LANGUAGE= OCO_MESSAGE_TEMPLATE_PLACEHOLDER= OCO_PROMPT_MODULE= OCO_ONE_LINE_COMMIT= +OCO_SKIP_COMMIT_CONFIRM= ``` Global configs are same as local configs, but they are stored in the global `~/.opencommit` config file and set with `oco config set` command, e.g. `oco config set OCO_MODEL=gpt-4o`. diff --git a/src/commands/commit.ts b/src/commands/commit.ts index f86016e4..d604ef4f 100644 --- a/src/commands/commit.ts +++ b/src/commands/commit.ts @@ -86,7 +86,7 @@ ${commitMessage} ${chalk.grey('——————————————————')}` ); - const userAction = skipCommitConfirmation + const userAction = skipCommitConfirmation || config.OCO_SKIP_COMMIT_CONFIRM ? 'Yes' : await select({ message: 'Confirm the commit message?', diff --git a/src/commands/config.ts b/src/commands/config.ts index 8bf98c36..1b126276 100644 --- a/src/commands/config.ts +++ b/src/commands/config.ts @@ -28,7 +28,8 @@ export enum CONFIG_KEYS { OCO_API_CUSTOM_HEADERS = 'OCO_API_CUSTOM_HEADERS', OCO_OMIT_SCOPE = 'OCO_OMIT_SCOPE', OCO_GITPUSH = 'OCO_GITPUSH', // todo: deprecate - OCO_HOOK_AUTO_UNCOMMENT = 'OCO_HOOK_AUTO_UNCOMMENT' + OCO_HOOK_AUTO_UNCOMMENT = 'OCO_HOOK_AUTO_UNCOMMENT', + OCO_SKIP_COMMIT_CONFIRM = 'OCO_SKIP_COMMIT_CONFIRM' } export enum CONFIG_MODES { @@ -827,6 +828,16 @@ export const configValidators = { typeof value === 'boolean', 'Must be true or false' ); + return value; + }, + + [CONFIG_KEYS.OCO_SKIP_COMMIT_CONFIRM](value: any) { + validateConfig( + CONFIG_KEYS.OCO_SKIP_COMMIT_CONFIRM, + typeof value === 'boolean', + 'Must be true or false' + ); + return value; } }; @@ -865,6 +876,7 @@ export type ConfigType = { [CONFIG_KEYS.OCO_OMIT_SCOPE]: boolean; [CONFIG_KEYS.OCO_TEST_MOCK_TYPE]: string; [CONFIG_KEYS.OCO_HOOK_AUTO_UNCOMMENT]: boolean; + [CONFIG_KEYS.OCO_SKIP_COMMIT_CONFIRM]: boolean; }; export const defaultConfigPath = pathJoin(homedir(), '.opencommit'); @@ -913,7 +925,8 @@ export const DEFAULT_CONFIG = { OCO_WHY: false, OCO_OMIT_SCOPE: false, OCO_GITPUSH: true, // todo: deprecate - OCO_HOOK_AUTO_UNCOMMENT: false + OCO_HOOK_AUTO_UNCOMMENT: false, + OCO_SKIP_COMMIT_CONFIRM: false }; const initGlobalConfig = (configPath: string = defaultConfigPath) => { @@ -954,7 +967,8 @@ const getEnvConfig = (envPath: string) => { OCO_TEST_MOCK_TYPE: process.env.OCO_TEST_MOCK_TYPE, OCO_OMIT_SCOPE: parseConfigVarValue(process.env.OCO_OMIT_SCOPE), - OCO_GITPUSH: parseConfigVarValue(process.env.OCO_GITPUSH) // todo: deprecate + OCO_GITPUSH: parseConfigVarValue(process.env.OCO_GITPUSH), // todo: deprecate + OCO_SKIP_COMMIT_CONFIRM: parseConfigVarValue(process.env.OCO_SKIP_COMMIT_CONFIRM) }; }; @@ -1170,6 +1184,11 @@ function getConfigKeyDetails(key) { description: 'Automatically uncomment the commit message in the hook', values: ['true', 'false'] }; + case CONFIG_KEYS.OCO_SKIP_COMMIT_CONFIRM: + return { + description: 'Skip the commit message confirmation prompt and auto-commit with generated message', + values: ['true', 'false'] + }; default: return { description: 'String value',