feat(packages): @sa/scripts: add ignore pattern list for command gitCommitVerify. close #504

This commit is contained in:
Soybean
2024-07-20 03:16:02 +08:00
parent 0206969e98
commit 958d0baf3f
4 changed files with 18 additions and 4 deletions

View File

@ -65,13 +65,15 @@ export async function gitCommit(lang: Lang = 'en-us') {
}
/** Git commit message verify */
export async function gitCommitVerify(lang: Lang = 'en-us') {
export async function gitCommitVerify(lang: Lang = 'en-us', ignores: RegExp[] = []) {
const gitPath = await execCommand('git', ['rev-parse', '--show-toplevel']);
const gitMsgPath = path.join(gitPath, '.git', 'COMMIT_EDITMSG');
const commitMsg = readFileSync(gitMsgPath, 'utf8').trim();
if (ignores.some(regExp => regExp.test(commitMsg))) return;
const REG_EXP = /(?<type>[a-z]+)(?:\((?<scope>.+)\))?(?<breaking>!)?: (?<description>.+)/i;
if (!REG_EXP.test(commitMsg)) {