MCPcopy Create free account
hub / github.com/Silentely/eSIM-Tools / validateCommitHeader

Function validateCommitHeader

scripts/commit-msg-lint.js:108–144  ·  view source on GitHub ↗
(header)

Source from the content-addressed store, hash-verified

106}
107
108function validateCommitHeader(header) {
109 if (!header) {
110 fail('提交标题为空。');
111 }
112
113 // 允许 git 自动生成的合并/回滚信息
114 if (header.startsWith('Merge ') || header.startsWith('Revert "')) {
115 return;
116 }
117
118 const firstSpaceIndex = header.indexOf(' ');
119 if (firstSpaceIndex <= 0) {
120 fail('缺少 emoji 前缀,或未使用空格分隔。');
121 }
122
123 const emojiToken = header.slice(0, firstSpaceIndex).trim();
124 const conventionalHeader = header.slice(firstSpaceIndex + 1).trim();
125
126 if (!isEmojiToken(emojiToken)) {
127 fail('提交标题需要以受支持的 emoji(或 :shortcode:)开头。');
128 }
129 validateEmojiToken(emojiToken);
130
131 const matched = conventionalHeader.match(HEADER_PATTERN);
132 if (!matched) {
133 fail(
134 `类型段不合法。请使用 ${COMMIT_TYPES.join(
135 ', '
136 )} 之一,并遵循 type(scope): subject 格式。`
137 );
138 }
139
140 const subject = matched[3].trim();
141 if (!/[\u3400-\u9FFF]/u.test(subject)) {
142 fail('提交描述必须包含中文字符。');
143 }
144}
145
146function main() {
147 const messageFilePath = process.argv[2];

Callers 1

mainFunction · 0.85

Calls 3

failFunction · 0.85
isEmojiTokenFunction · 0.85
validateEmojiTokenFunction · 0.85

Tested by

no test coverage detected