Skip to content

feat(config.ts): add skipCommitMessageCheck config key #19

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 3 commits 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
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,12 @@ To unset the hook:
oc hook unset
```

In the hook, there is a check that checks if the commit message is not empty. If it is not, the hook will not run. To skip that check and always replace the commit message run:

```sh
oc config set skipCommitMsgHookSourceCheck=true
```

To use the hook:

```sh
Expand Down
14 changes: 12 additions & 2 deletions src/commands/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ import { COMMANDS } from '../CommandsEnum';
export enum CONFIG_KEYS {
OPENAI_API_KEY = 'OPENAI_API_KEY',
description = 'description',
emoji = 'emoji'
emoji = 'emoji',
skipCommitMsgHookSourceCheck = 'skipCommitMsgHookSourceCheck'
}

export enum CONFIG_MODES {
Expand Down Expand Up @@ -64,7 +65,16 @@ export const configValidators = {
);

return value;
}
},
[CONFIG_KEYS.skipCommitMsgHookSourceCheck](value: any) {
validateConfig(
CONFIG_KEYS.skipCommitMsgHookSourceCheck,
typeof value === 'boolean',
'Must be true or false'
);

return value;
},
};

export type ConfigType = {
Expand Down
7 changes: 4 additions & 3 deletions src/commands/prepare-commit-msg-hook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,17 @@ export const prepareCommitMessageHook = async () => {
);
}

if (commitSource) return;
const config = getConfig();

// Skip commit message check if the user has set the skipCommitMessageCheck flag to true
if (!config?.skipCommitMsgHookSourceCheck && commitSource) return;

const staged = await getStagedGitDiff();

if (!staged) return;

intro('opencommit');

const config = getConfig();

if (!config?.OPENAI_API_KEY) {
throw new Error(
'No OPEN_AI_API exists. Set your OPEN_AI_API=<key> in ~/.opencommit'
Expand Down