Files
shtil/tools/git-hooks/commit-msg.mjs
T
TMSHandDevin dcee1faf7d chore: добавлены правила git, шаблон PR и проверочные хуки (#4)
Правила работы с ветками, коммитами и PR в docs/contributing.md. Lefthook проверяет формат коммита, форматирует Go и ищет секреты перед коммитом.

Refs: 1.2.8, 1.2.9, 1.2.10, 1.13.4

Generated with [Devin](https://devin.ai)

Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Reviewed-on: #4
Co-authored-by: BrowenSiz <top.timashevsky@gmail.com>
2026-11-08 15:35:13 +00:00

33 lines
2.1 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/usr/bin/env node
// Проверка сообщения коммита по правилам docs/contributing.md. Вызывается lefthook (commit-msg).
import { readFileSync } from 'node:fs';
const TYPES = ['feat', 'fix', 'docs', 'chore', 'refactor', 'test', 'perf', 'build', 'ci', 'style', 'revert'];
const SCOPES = ['server', 'agent', 'helper', 'console', 'ui', 'proto', 'api', 'db', 'ci', 'docs', 'roadmap', 'tools', 'deps'];
const HEADER = new RegExp(`^(${TYPES.join('|')})(\\((${SCOPES.join('|')})\\))?!?: (.+)$`);
const REFS = /^Refs: \d+(\.\d+)+(, ?\d+(\.\d+)+)*$/m;
const lines = readFileSync(process.argv[2], 'utf8').split(/\r?\n/).filter(l => !l.startsWith('#'));
const msg = lines.join('\n').trim();
const header = lines[0]?.trim() ?? '';
if (/^(Merge|Revert|fixup!|squash!|amend!) /.test(header)) process.exit(0);
const errors = [];
const m = header.match(HEADER);
if (!m) errors.push(`заголовок должен быть «тип(область): что сделано».\n Типы: ${TYPES.join(', ')}\n Области: ${SCOPES.join(', ')}`);
else {
const desc = m[4];
if (!/[а-яё]/i.test(desc)) errors.push('описание пишется по-русски');
if (/^[А-ЯЁ]/.test(desc)) errors.push('описание начинается с маленькой буквы');
if (/\.$/.test(desc)) errors.push('в конце заголовка не ставится точка');
}
if ([...header].length > 72) errors.push(`заголовок длиннее 72 символов (${[...header].length})`);
if (lines[1]?.trim()) errors.push('после заголовка нужна пустая строка');
if (!REFS.test(msg)) errors.push('нет строки «Refs: <ID пункта>», например «Refs: 2.11.4» или «Refs: 1.2.8, 1.2.9»');
if (errors.length) {
console.error(`\nКоммит отклонён: «${header}»\n${errors.map(e => ' - ' + e).join('\n')}\n\nПример:\n feat(server): добавлен WithTenantTx для доступа к данным организации\n\n Refs: 2.11.4\n\nПравила — docs/contributing.md\n`);
process.exit(1);
}