✨ feat: adding new additions to linter scripts
This commit is contained in:
parent
45fe8a0c11
commit
2e3d45063d
@ -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);
|
||||||
|
@ -16,9 +16,9 @@ const { execSync } = require('child_process');
|
|||||||
if (changes) {
|
if (changes) {
|
||||||
spinner.succeed('Changes detected.');
|
spinner.succeed('Changes detected.');
|
||||||
// Read the latest commit message to ensure uniqueness
|
// Read the latest commit message to ensure uniqueness
|
||||||
const latestCommitMessage = execSync('git log -1 --pretty=%B', {
|
const latestCommitMessage = execSync(`git log -n 100 --pretty=format:%s`)
|
||||||
encoding: 'utf-8',
|
.toString()
|
||||||
}).trim();
|
.split('\n');
|
||||||
|
|
||||||
// Generate a unique commit message
|
// Generate a unique commit message
|
||||||
let commitMessage = 'style: format with prettier';
|
let commitMessage = 'style: format with prettier';
|
||||||
|
Loading…
x
Reference in New Issue
Block a user