6130-commitLint #1792

Merged
pablone merged 31 commits from 6130-commitLint into dev 2024-04-12 11:02:00 +00:00
4 changed files with 42 additions and 7 deletions
Showing only changes of commit 42e21eb602 - Show all commits

View File

@ -1,6 +0,0 @@
{
"extends": ["@commitlint/config-conventional"],
"rules": {
"type-enum": [2, "always", ["ci", "chore", "docs", "ticket","feat", "fix", "perf", "refactor", "revert", "style", "test"]]
}
}

36
.husky/addReferenceTag.js Normal file
View File

@ -0,0 +1,36 @@
const fs = require('fs');
const path = require('path');
async function getCurrentBranchName(p = process.cwd()) {
while (p !== path.parse(p).root) {
const gitHeadPath = path.join(p, '.git', 'HEAD');
try {
const headContent = await fs.readFile(gitHeadPath, 'utf-8');
return headContent.trim().split('/')[2];
} catch (err) {
p = path.resolve(p, '..');
}
}
return false;
}
const branchName = getCurrentBranchName();
if (branchName) {
const msgPath = `.git/COMMIT_EDITMSG`;
const msg = fs.readFileSync(msgPath, "utf-8");
const referenceTag = `refs #${branchName.match(/^\d+/)}`;
console.log('referenceTag: ', referenceTag);
console.log(msg);
if (!msg.includes(referenceTag)) {
const splitedMsg = msg.split(':');
if (splitedMsg.length > 1) {
const finalMsg = splitedMsg[0] + splitedMsg.slice(1).join(':');
fs.writeFileSync(msgPath, finalMsg);
}
}
}

View File

@ -1,4 +1,8 @@
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"
echo "Running husky commit-msg hook"
npx --no-install commitlint --edit
echo "Adding reference tag to commit message"
pnpm run addReferenceTag

View File

@ -115,7 +115,8 @@
"back": "nodemon --inspect -w modules ./node_modules/gulp/bin/gulp.js back",
"lint": "eslint ./ --cache --ignore-pattern .gitignore",
"commitlint": "commitlint --edit",
"prepare": "husky install"
"prepare": "husky install",
"addReferenceTag": "node .husky/addReferenceTag.js"
},
"jest": {
"projects": [