msg.js 969 B

1234567891011121314151617
  1. /** commit 信息规范: [业务域/页面名] 动作: 摘要 (动作 ∈ 新增|重构|更新|修复|标注|元数据|初始化|门户)
  2. * 已合规则原样;不合规则自动包装(从暂存清单推页面名,新文件判"新增") */
  3. const MSG_RE = /^\[[^\]]+\]\s*(新增|重构|更新|修复|标注|元数据|初始化|门户)\s*[::]/;
  4. export function normalizeMsg(rawMsg, stagedLines) {
  5. const m = (rawMsg || "").trim();
  6. if (MSG_RE.test(m)) return m;
  7. const pageFiles = stagedLines.map(l => l.slice(3).trim()).filter(f => /\.html?$/i.test(f));
  8. let scope;
  9. if (pageFiles.length === 1) scope = pageFiles[0].replace(/\.html?$/i, "");
  10. else if (pageFiles.length > 1) {
  11. const dirs = pageFiles.map(f => f.split("/")[0]);
  12. scope = dirs.every(d => d === dirs[0]) ? dirs[0] : "原型库";
  13. } else scope = "原型库";
  14. const action = stagedLines.some(l => /^A/.test(l)) ? "新增" : "更新";
  15. return `[${scope}] ${action}: ${m || "原型改动"}`;
  16. }