Skip to content

Commit 4cc31a7

Browse files
committed
feat: add configuration option to skip commit confirmation prompt
1 parent 8ae2f7d commit 4cc31a7

File tree

3 files changed

+30
-4
lines changed

3 files changed

+30
-4
lines changed

README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,12 @@ This flag allows users to automatically commit the changes without having to man
9898
oco --yes
9999
```
100100

101+
You can also set this behavior permanently through configuration:
102+
103+
```
104+
oco config set OCO_SKIP_COMMIT_CONFIRM=true
105+
```
106+
101107
## Configuration
102108

103109
### Local per repo configuration
@@ -119,6 +125,7 @@ OCO_LANGUAGE=<locale, scroll to the bottom to see options>
119125
OCO_MESSAGE_TEMPLATE_PLACEHOLDER=<message template placeholder, default: '$msg'>
120126
OCO_PROMPT_MODULE=<either conventional-commit or @commitlint, default: conventional-commit>
121127
OCO_ONE_LINE_COMMIT=<one line commit message, default: false>
128+
OCO_SKIP_COMMIT_CONFIRM=<skip commit confirmation prompt, default: false>
122129
```
123130

124131
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`.

src/commands/commit.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ ${commitMessage}
8686
${chalk.grey('——————————————————')}`
8787
);
8888

89-
const userAction = skipCommitConfirmation
89+
const userAction = skipCommitConfirmation || config.OCO_SKIP_COMMIT_CONFIRM
9090
? 'Yes'
9191
: await select({
9292
message: 'Confirm the commit message?',

src/commands/config.ts

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ export enum CONFIG_KEYS {
2828
OCO_API_CUSTOM_HEADERS = 'OCO_API_CUSTOM_HEADERS',
2929
OCO_OMIT_SCOPE = 'OCO_OMIT_SCOPE',
3030
OCO_GITPUSH = 'OCO_GITPUSH', // todo: deprecate
31-
OCO_HOOK_AUTO_UNCOMMENT = 'OCO_HOOK_AUTO_UNCOMMENT'
31+
OCO_HOOK_AUTO_UNCOMMENT = 'OCO_HOOK_AUTO_UNCOMMENT',
32+
OCO_SKIP_COMMIT_CONFIRM = 'OCO_SKIP_COMMIT_CONFIRM'
3233
}
3334

3435
export enum CONFIG_MODES {
@@ -827,6 +828,16 @@ export const configValidators = {
827828
typeof value === 'boolean',
828829
'Must be true or false'
829830
);
831+
return value;
832+
},
833+
834+
[CONFIG_KEYS.OCO_SKIP_COMMIT_CONFIRM](value: any) {
835+
validateConfig(
836+
CONFIG_KEYS.OCO_SKIP_COMMIT_CONFIRM,
837+
typeof value === 'boolean',
838+
'Must be true or false'
839+
);
840+
return value;
830841
}
831842
};
832843

@@ -865,6 +876,7 @@ export type ConfigType = {
865876
[CONFIG_KEYS.OCO_OMIT_SCOPE]: boolean;
866877
[CONFIG_KEYS.OCO_TEST_MOCK_TYPE]: string;
867878
[CONFIG_KEYS.OCO_HOOK_AUTO_UNCOMMENT]: boolean;
879+
[CONFIG_KEYS.OCO_SKIP_COMMIT_CONFIRM]: boolean;
868880
};
869881

870882
export const defaultConfigPath = pathJoin(homedir(), '.opencommit');
@@ -913,7 +925,8 @@ export const DEFAULT_CONFIG = {
913925
OCO_WHY: false,
914926
OCO_OMIT_SCOPE: false,
915927
OCO_GITPUSH: true, // todo: deprecate
916-
OCO_HOOK_AUTO_UNCOMMENT: false
928+
OCO_HOOK_AUTO_UNCOMMENT: false,
929+
OCO_SKIP_COMMIT_CONFIRM: false
917930
};
918931

919932
const initGlobalConfig = (configPath: string = defaultConfigPath) => {
@@ -954,7 +967,8 @@ const getEnvConfig = (envPath: string) => {
954967
OCO_TEST_MOCK_TYPE: process.env.OCO_TEST_MOCK_TYPE,
955968
OCO_OMIT_SCOPE: parseConfigVarValue(process.env.OCO_OMIT_SCOPE),
956969

957-
OCO_GITPUSH: parseConfigVarValue(process.env.OCO_GITPUSH) // todo: deprecate
970+
OCO_GITPUSH: parseConfigVarValue(process.env.OCO_GITPUSH), // todo: deprecate
971+
OCO_SKIP_COMMIT_CONFIRM: parseConfigVarValue(process.env.OCO_SKIP_COMMIT_CONFIRM)
958972
};
959973
};
960974

@@ -1170,6 +1184,11 @@ function getConfigKeyDetails(key) {
11701184
description: 'Automatically uncomment the commit message in the hook',
11711185
values: ['true', 'false']
11721186
};
1187+
case CONFIG_KEYS.OCO_SKIP_COMMIT_CONFIRM:
1188+
return {
1189+
description: 'Skip the commit message confirmation prompt and auto-commit with generated message',
1190+
values: ['true', 'false']
1191+
};
11731192
default:
11741193
return {
11751194
description: 'String value',

0 commit comments

Comments
 (0)