Skip to content

Commit ba07424

Browse files
committed
refactor(cli): enhance pre-commit hook functionality
1 parent de8723c commit ba07424

2 files changed

Lines changed: 28 additions & 5 deletions

File tree

src/cli.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,15 @@ cli(
173173
await initializeLogger(config);
174174
logger.info(`aicommit2 version: ${version}`);
175175
if (argv.flags['pre-commit']) {
176-
preCommitHook(argv.flags.verbose);
176+
preCommitHook(
177+
argv.flags.locale,
178+
argv.flags.generate,
179+
argv.flags.exclude,
180+
argv.flags.type,
181+
argv.flags.prompt,
182+
argv.flags['include-body'],
183+
argv.flags.verbose
184+
);
177185
return;
178186
}
179187

src/commands/pre-commit-hook.ts

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,15 @@ import { getBranchName, getStagedDiff } from '../utils/vcs.js';
1313
const args = process.argv.slice(2).filter(arg => !arg.startsWith('--pre-commit'));
1414
const [messageFilePath, commitSource] = args;
1515

16-
export default (verbose = false) =>
16+
export default (
17+
locale: string | undefined,
18+
generate: number | undefined,
19+
excludeFiles: string[],
20+
commitType: string | undefined,
21+
prompt: string | undefined,
22+
includeBody: boolean | undefined,
23+
verbose: boolean
24+
) =>
1725
(async () => {
1826
if (!messageFilePath) {
1927
throw new KnownError('Commit message file path is missing. This file should be called from the "pre-commit framework"');
@@ -34,12 +42,19 @@ export default (verbose = false) =>
3442
const consoleManager = new ConsoleManager();
3543
consoleManager.printTitle();
3644

37-
const cliOverrides: RawConfig = {};
45+
const configOverrides: RawConfig = {
46+
...(locale && { locale }),
47+
...(generate != null && { generate: generate.toString() }),
48+
...(commitType && { type: commitType }),
49+
...(prompt && { systemPrompt: prompt }),
50+
...(includeBody === true && { includeBody: 'true' }),
51+
};
52+
3853
if (verbose) {
39-
cliOverrides.logLevel = 'verbose';
54+
configOverrides.logLevel = 'verbose';
4055
}
4156

42-
const config = await getConfig(cliOverrides);
57+
const config = await getConfig(configOverrides, excludeFiles);
4358
if (config.systemPromptPath) {
4459
try {
4560
await fs.readFile(path.resolve(config.systemPromptPath), 'utf-8');

0 commit comments

Comments
 (0)