Skip to content

Commit 3a255a3

Browse files
committed
feat(config): add OCO_HOOK_AUTO_UNCOMMENT config key and update commit message hook behavior to conditionally uncomment the message
1 parent 9971b3c commit 3a255a3

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

src/commands/config.ts

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ export enum CONFIG_KEYS {
2727
OCO_API_URL = 'OCO_API_URL',
2828
OCO_API_CUSTOM_HEADERS = 'OCO_API_CUSTOM_HEADERS',
2929
OCO_OMIT_SCOPE = 'OCO_OMIT_SCOPE',
30-
OCO_GITPUSH = 'OCO_GITPUSH' // todo: deprecate
30+
OCO_GITPUSH = 'OCO_GITPUSH', // todo: deprecate
31+
OCO_HOOK_AUTO_UNCOMMENT = 'OCO_HOOK_AUTO_UNCOMMENT'
3132
}
3233

3334
export enum CONFIG_MODES {
@@ -711,6 +712,14 @@ export const configValidators = {
711712
'Must be true or false'
712713
);
713714
return value;
715+
},
716+
717+
[CONFIG_KEYS.OCO_HOOK_AUTO_UNCOMMENT](value: any) {
718+
validateConfig(
719+
CONFIG_KEYS.OCO_HOOK_AUTO_UNCOMMENT,
720+
typeof value === 'boolean',
721+
'Must be true or false'
722+
);
714723
}
715724
};
716725

@@ -747,6 +756,7 @@ export type ConfigType = {
747756
[CONFIG_KEYS.OCO_ONE_LINE_COMMIT]: boolean;
748757
[CONFIG_KEYS.OCO_OMIT_SCOPE]: boolean;
749758
[CONFIG_KEYS.OCO_TEST_MOCK_TYPE]: string;
759+
[CONFIG_KEYS.OCO_HOOK_AUTO_UNCOMMENT]: boolean;
750760
};
751761

752762
export const defaultConfigPath = pathJoin(homedir(), '.opencommit');
@@ -794,7 +804,8 @@ export const DEFAULT_CONFIG = {
794804
OCO_TEST_MOCK_TYPE: 'commit-message',
795805
OCO_WHY: false,
796806
OCO_OMIT_SCOPE: false,
797-
OCO_GITPUSH: true // todo: deprecate
807+
OCO_GITPUSH: true, // todo: deprecate
808+
OCO_HOOK_AUTO_UNCOMMENT: false
798809
};
799810

800811
const initGlobalConfig = (configPath: string = defaultConfigPath) => {
@@ -1046,6 +1057,11 @@ function getConfigKeyDetails(key) {
10461057
description: 'Message template placeholder',
10471058
values: ['String (must start with $)']
10481059
};
1060+
case CONFIG_KEYS.OCO_HOOK_AUTO_UNCOMMENT:
1061+
return {
1062+
description: 'Automatically uncomment the commit message in the hook',
1063+
values: ['true', 'false']
1064+
};
10491065
default:
10501066
return {
10511067
description: 'String value',

src/commands/prepare-commit-msg-hook.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ export const prepareCommitMessageHook = async (
6060

6161
await fs.writeFile(
6262
messageFilePath,
63-
`# ${commitMessage}\n\n${divider}\n# Remove the # above to use this generated commit message.\n# To cancel the commit, just close this window without making any changes.\n\n${fileContent.toString()}`
63+
`${config.OCO_HOOK_AUTO_UNCOMMENT ? '' : '# '}${commitMessage}\n\n${divider}\n# Remove the # above to use this generated commit message.\n# To cancel the commit, just close this window without making any changes.\n\n${fileContent.toString()}`
6464
);
6565
} catch (error) {
6666
outro(`${chalk.red('✖')} ${error}`);

0 commit comments

Comments
 (0)