Skip to content
Merged
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
20 changes: 18 additions & 2 deletions src/commands/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ export enum CONFIG_KEYS {
OCO_API_URL = 'OCO_API_URL',
OCO_API_CUSTOM_HEADERS = 'OCO_API_CUSTOM_HEADERS',
OCO_OMIT_SCOPE = 'OCO_OMIT_SCOPE',
OCO_GITPUSH = 'OCO_GITPUSH' // todo: deprecate
OCO_GITPUSH = 'OCO_GITPUSH', // todo: deprecate
OCO_HOOK_AUTO_UNCOMMENT = 'OCO_HOOK_AUTO_UNCOMMENT'
}

export enum CONFIG_MODES {
Expand Down Expand Up @@ -711,6 +712,14 @@ export const configValidators = {
'Must be true or false'
);
return value;
},

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

Expand Down Expand Up @@ -747,6 +756,7 @@ export type ConfigType = {
[CONFIG_KEYS.OCO_ONE_LINE_COMMIT]: boolean;
[CONFIG_KEYS.OCO_OMIT_SCOPE]: boolean;
[CONFIG_KEYS.OCO_TEST_MOCK_TYPE]: string;
[CONFIG_KEYS.OCO_HOOK_AUTO_UNCOMMENT]: boolean;
};

export const defaultConfigPath = pathJoin(homedir(), '.opencommit');
Expand Down Expand Up @@ -794,7 +804,8 @@ export const DEFAULT_CONFIG = {
OCO_TEST_MOCK_TYPE: 'commit-message',
OCO_WHY: false,
OCO_OMIT_SCOPE: false,
OCO_GITPUSH: true // todo: deprecate
OCO_GITPUSH: true, // todo: deprecate
OCO_HOOK_AUTO_UNCOMMENT: false
};

const initGlobalConfig = (configPath: string = defaultConfigPath) => {
Expand Down Expand Up @@ -1046,6 +1057,11 @@ function getConfigKeyDetails(key) {
description: 'Message template placeholder',
values: ['String (must start with $)']
};
case CONFIG_KEYS.OCO_HOOK_AUTO_UNCOMMENT:
return {
description: 'Automatically uncomment the commit message in the hook',
values: ['true', 'false']
};
default:
return {
description: 'String value',
Expand Down
12 changes: 7 additions & 5 deletions src/commands/prepare-commit-msg-hook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,14 @@ export const prepareCommitMessageHook = async (

const fileContent = await fs.readFile(messageFilePath);

const divider = '# ---------- [OpenCommit] ---------- #';
const messageWithComment = `# ${commitMessage}\n\n# ---------- [OpenCommit] ---------- #\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()}`;
const messageWithoutComment = `${commitMessage}\n\n${fileContent.toString()}`;

await fs.writeFile(
messageFilePath,
`# ${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()}`
);
const message = config.OCO_HOOK_AUTO_UNCOMMENT
? messageWithoutComment
: messageWithComment;

await fs.writeFile(messageFilePath, message);
} catch (error) {
outro(`${chalk.red('✖')} ${error}`);
process.exit(1);
Expand Down
2 changes: 1 addition & 1 deletion src/migrations/_run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export const runMigrations = async () => {
OCO_AI_PROVIDER_ENUM.GROQ,
OCO_AI_PROVIDER_ENUM.MISTRAL,
OCO_AI_PROVIDER_ENUM.MLX,
OCO_AI_PROVIDER_ENUM.OPENROUTER,
OCO_AI_PROVIDER_ENUM.OPENROUTER
].includes(config.OCO_AI_PROVIDER)
) {
return;
Expand Down