You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
rakit/scripts/verify-commit.js

29 lines
1.4 KiB

// @ts-check
import pico from "picocolors";
import { readFileSync } from "node:fs";
import path from "node:path";
const msgPath = path.resolve(".git/COMMIT_EDITMSG");
const msg = readFileSync(msgPath, "utf-8").trim();
const commitRE = /^(revert: )?(feat|fix|docs|dx|style|refactor|perf|test|workflow|build|ci|chore|types|wip|release)((.+))?: .{1,50}/;
if (!commitRE.test(msg)) {
console.log(pico.yellow(`\n您提交的信息: ${msg}\n`));
console.error(
` ${pico.white(pico.bgRed(" 错误 "))} ${pico.red(`无效的提交信息格式.`)}\n\n` +
` ${pico.red(`自动生成变更日志需要正确的提交消息格式. 例如:`)}\n\n` +
` ${pico.green(`feat(auth): 新功能`)}\n` +
` ${pico.green(`fix(i18n): 修复 (close #28)`)}\n` +
` ${pico.green(`docs: 文档变更`)}\n` +
` ${pico.green(`style: 代码格式(不影响代码运行的变动)`)}\n` +
` ${pico.green(`refactor: 重构(既不是增加feature,也不是修复bug)`)}\n` +
` ${pico.green(`perf: 性能优化`)}\n` +
` ${pico.green(`test: 增加测试`)}\n` +
` ${pico.green(`chore: 构建过程或辅助工具的变动`)}\n` +
` ${pico.green(`revert: 回退`)}\n` +
` ${pico.green(`buid: 打包`)}\n\n` +
pico.red(` See .github/commit-convention.md for more details.\n\n`)
);
process.exit(1);
}