🐛 fix: fixing script on commit message

This commit is contained in:
Carlos
2024-08-13 20:49:35 -04:00
parent 269518c264
commit c588022933

View File

@ -40,15 +40,44 @@ async function run() {
// Check for duplicate commit messages in the last 100 commits // Check for duplicate commit messages in the last 100 commits
const duplicateCommitMsg = execSync(`git log -n 100 --pretty=format:%s`) const duplicateCommitMsg = execSync(`git log -n 100 --pretty=format:%s`)
.toString() .toString()
.split('\n') .split('\n');
.some((msg) => msg.trim() === commitMsg);
if (duplicateCommitMsg) { // Extract emojis from commitTypes
spinner.fail('❌ Duplicate commit message detected.'); const emojis = Object.values(commitTypes);
// Function to remove an emoji or the default emoji from the start of the string
const removeEmoji = (message) => {
for (const emoji of emojis) {
// Check if the message starts with the emoji
if (message.startsWith(emoji)) {
return message.slice(emoji.length).trim();
}
}
// Check if the message starts with the default emoji
if (message.startsWith(defaultEmoji)) {
return message.slice(defaultEmoji.length).trim();
}
// Return the message as is if it doesn't start with an emoji
return message;
};
// Apply the function to each message
const cleanMessages = duplicateCommitMsg.map(removeEmoji);
if (cleanMessages.includes(commitMsg)) {
spinner.fail(chalk.bold.red('Duplicate Commit Detected'));
console.log();
console.error( console.error(
chalk.red( chalk.white.bgRed.bold(' ERROR: ') +
'❌ Duplicate commit message detected. Please use a unique commit message.' chalk.redBright(' A duplicate commit message has been detected.')
) );
console.log();
console.log(
chalk.yellowBright('💡 TIP: ') +
chalk.white(
' Please use a unique commit message to keep the history clean.'
)
); );
console.log(); console.log();
process.exit(1); process.exit(1);