6130-commitLint #1792
|
@ -1,6 +0,0 @@
|
|||
{
|
||||
"extends": ["@commitlint/config-conventional"],
|
||||
"rules": {
|
||||
"type-enum": [2, "always", ["ci", "chore", "docs", "ticket","feat", "fix", "perf", "refactor", "revert", "style", "test"]]
|
||||
}
|
||||
}
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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": [
|
||||
|
|
Loading…
Reference in New Issue