fix(prepare-commit-msg-hook): simplify commit message generation logic for clarity and maintainability
This commit is contained in:
@@ -56,12 +56,14 @@ export const prepareCommitMessageHook = async (
|
|||||||
|
|
||||||
const fileContent = await fs.readFile(messageFilePath);
|
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(
|
const message = config.OCO_HOOK_AUTO_UNCOMMENT
|
||||||
messageFilePath,
|
? messageWithoutComment
|
||||||
`${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()}`
|
: messageWithComment;
|
||||||
);
|
|
||||||
|
await fs.writeFile(messageFilePath, message);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
outro(`${chalk.red('✖')} ${error}`);
|
outro(`${chalk.red('✖')} ${error}`);
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
|
|||||||
Reference in New Issue
Block a user