Skip to content

feat(config): Add options to skip commit and push prompts #504

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

Open
wants to merge 1 commit into
base: dev
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 README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -119,6 +125,7 @@ OCO_LANGUAGE=<locale, scroll to the bottom to see options>
OCO_MESSAGE_TEMPLATE_PLACEHOLDER=<message template placeholder, default: '$msg'>
OCO_PROMPT_MODULE=<either conventional-commit or @commitlint, default: conventional-commit>
OCO_ONE_LINE_COMMIT=<one line commit message, default: false>
OCO_SKIP_COMMIT_CONFIRM=<skip commit confirmation prompt, default: false>
```

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`.
Expand Down
2 changes: 1 addition & 1 deletion src/commands/commit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ ${commitMessage}
${chalk.grey('——————————————————')}`
);

const userAction = skipCommitConfirmation
const userAction = skipCommitConfirmation || config.OCO_SKIP_COMMIT_CONFIRM
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

aint skipCommitConfirmation does exactly what you also implemented?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Author

@Sma1lboy Sma1lboy Aug 9, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm so sorry for late response. You're right, but I really prefer to put it at the config level rather than using oco --yes every time, although I could create an alias in my shell environment. 🤔

From another perspective, I want to keep the config standard and make this content worthy of being managed through config for a unified trigger process.

? 'Yes'
: await select({
message: 'Confirm the commit message?',
Expand Down
25 changes: 22 additions & 3 deletions src/commands/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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;
}
};

Expand Down Expand Up @@ -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');
Expand Down Expand Up @@ -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) => {
Expand Down Expand Up @@ -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)
};
};

Expand Down Expand Up @@ -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',
Expand Down
Loading