Skip to content

Commit 6fc7274

Browse files
committed
feat(config): add OCO_SKIP_COMMIT_CONFIRM to skip confirmation prompt
feat(config): add OCO_SKIP_PUSH_PROMPT to skip push prompt refactor(commit): use config.OCO_SKIP_COMMIT_CONFIRM instead of direct skipCommitConfirmation refactor(commit): use config.OCO_SKIP_PUSH_PROMPT to control git push behavior
1 parent c1756b8 commit 6fc7274

File tree

2 files changed

+41
-5
lines changed

2 files changed

+41
-5
lines changed

src/commands/commit.ts

Lines changed: 2 additions & 2 deletions
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?',
@@ -126,7 +126,7 @@ ${chalk.grey('——————————————————')}`
126126
const remotes = await getGitRemotes();
127127

128128
// user isn't pushing, return early
129-
if (config.OCO_GITPUSH === false) return;
129+
if (config.OCO_GITPUSH === false || config.OCO_SKIP_PUSH_PROMPT === true) return;
130130

131131
if (!remotes.length) {
132132
const { stdout } = await execa('git', ['push']);

src/commands/config.ts

Lines changed: 39 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,9 @@ 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',
33+
OCO_SKIP_PUSH_PROMPT = 'OCO_SKIP_PUSH_PROMPT'
3234
}
3335

3436
export enum CONFIG_MODES {
@@ -720,6 +722,24 @@ export const configValidators = {
720722
typeof value === 'boolean',
721723
'Must be true or false'
722724
);
725+
},
726+
727+
[CONFIG_KEYS.OCO_SKIP_COMMIT_CONFIRM](value: any) {
728+
validateConfig(
729+
CONFIG_KEYS.OCO_SKIP_COMMIT_CONFIRM,
730+
typeof value === 'boolean',
731+
'Must be true or false'
732+
);
733+
return value;
734+
},
735+
736+
[CONFIG_KEYS.OCO_SKIP_PUSH_PROMPT](value: any) {
737+
validateConfig(
738+
CONFIG_KEYS.OCO_SKIP_PUSH_PROMPT,
739+
typeof value === 'boolean',
740+
'Must be true or false'
741+
);
742+
return value;
723743
}
724744
};
725745

@@ -757,6 +777,8 @@ export type ConfigType = {
757777
[CONFIG_KEYS.OCO_OMIT_SCOPE]: boolean;
758778
[CONFIG_KEYS.OCO_TEST_MOCK_TYPE]: string;
759779
[CONFIG_KEYS.OCO_HOOK_AUTO_UNCOMMENT]: boolean;
780+
[CONFIG_KEYS.OCO_SKIP_COMMIT_CONFIRM]: boolean;
781+
[CONFIG_KEYS.OCO_SKIP_PUSH_PROMPT]: boolean;
760782
};
761783

762784
export const defaultConfigPath = pathJoin(homedir(), '.opencommit');
@@ -805,7 +827,9 @@ export const DEFAULT_CONFIG = {
805827
OCO_WHY: false,
806828
OCO_OMIT_SCOPE: false,
807829
OCO_GITPUSH: true, // todo: deprecate
808-
OCO_HOOK_AUTO_UNCOMMENT: false
830+
OCO_HOOK_AUTO_UNCOMMENT: false,
831+
OCO_SKIP_COMMIT_CONFIRM: false,
832+
OCO_SKIP_PUSH_PROMPT: false
809833
};
810834

811835
const initGlobalConfig = (configPath: string = defaultConfigPath) => {
@@ -846,7 +870,9 @@ const getEnvConfig = (envPath: string) => {
846870
OCO_TEST_MOCK_TYPE: process.env.OCO_TEST_MOCK_TYPE,
847871
OCO_OMIT_SCOPE: parseConfigVarValue(process.env.OCO_OMIT_SCOPE),
848872

849-
OCO_GITPUSH: parseConfigVarValue(process.env.OCO_GITPUSH) // todo: deprecate
873+
OCO_GITPUSH: parseConfigVarValue(process.env.OCO_GITPUSH), // todo: deprecate
874+
OCO_SKIP_COMMIT_CONFIRM: parseConfigVarValue(process.env.OCO_SKIP_COMMIT_CONFIRM),
875+
OCO_SKIP_PUSH_PROMPT: parseConfigVarValue(process.env.OCO_SKIP_PUSH_PROMPT)
850876
};
851877
};
852878

@@ -1062,6 +1088,16 @@ function getConfigKeyDetails(key) {
10621088
description: 'Automatically uncomment the commit message in the hook',
10631089
values: ['true', 'false']
10641090
};
1091+
case CONFIG_KEYS.OCO_SKIP_COMMIT_CONFIRM:
1092+
return {
1093+
description: 'Skip the commit message confirmation prompt and auto-commit with generated message',
1094+
values: ['true', 'false']
1095+
};
1096+
case CONFIG_KEYS.OCO_SKIP_PUSH_PROMPT:
1097+
return {
1098+
description: 'Skip the git push prompt and never ask to push after committing',
1099+
values: ['true', 'false']
1100+
};
10651101
default:
10661102
return {
10671103
description: 'String value',

0 commit comments

Comments
 (0)