mirror of
https://github.com/Silentely/eSIM-Tools.git
synced 2026-09-03 06:24:20 +08:00
🔧 chore(hooks): 新增提交与推送质量门禁
This commit is contained in:
54
scripts/prepare-commit-msg.js
Normal file
54
scripts/prepare-commit-msg.js
Normal file
@@ -0,0 +1,54 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
/**
|
||||
* prepare-commit-msg:
|
||||
* 在未填写提交信息时,注入标准模板,降低格式输入错误概率。
|
||||
*/
|
||||
|
||||
const fs = require('fs');
|
||||
|
||||
const TEMPLATE_HEADER = '✨ feat(core): 请填写中文描述';
|
||||
const SKIP_SOURCES = new Set(['merge', 'squash', 'commit']);
|
||||
|
||||
function getFirstMeaningfulLine(content) {
|
||||
const lines = content.split(/\r?\n/);
|
||||
for (const line of lines) {
|
||||
const trimmed = line.trim();
|
||||
if (!trimmed || trimmed.startsWith('#')) {
|
||||
continue;
|
||||
}
|
||||
return trimmed;
|
||||
}
|
||||
return '';
|
||||
}
|
||||
|
||||
function main() {
|
||||
const messageFilePath = process.argv[2];
|
||||
const commitSource = process.argv[3] || '';
|
||||
|
||||
if (!messageFilePath || SKIP_SOURCES.has(commitSource)) {
|
||||
return;
|
||||
}
|
||||
|
||||
const original = fs.readFileSync(messageFilePath, 'utf8');
|
||||
const firstLine = getFirstMeaningfulLine(original);
|
||||
if (firstLine) {
|
||||
return;
|
||||
}
|
||||
|
||||
const commentLines = original
|
||||
.split(/\r?\n/)
|
||||
.filter(line => line.trim().startsWith('#'));
|
||||
|
||||
const content = [
|
||||
TEMPLATE_HEADER,
|
||||
'',
|
||||
'# 格式: <emoji> <type>(optional-scope): <中文描述>',
|
||||
'# 示例: 🐛 fix(simyo): 修复验证码重试逻辑',
|
||||
...commentLines
|
||||
].join('\n');
|
||||
|
||||
fs.writeFileSync(messageFilePath, content, 'utf8');
|
||||
}
|
||||
|
||||
main();
|
||||
Reference in New Issue
Block a user