Files
ghbot/scripts/husky-pre-commit.cjs
T
lezi-fun 9e47ab339e feat: sync ghbot-Nodeloc v1.2.0 capabilities into upstream
Merges all 33 commits from lza6/ghbot-Nodeloc (v1.0.0 through v1.2.0)
while keeping both sides' features in every conflicted file:

- EventRouter dispatch extracted from runReview.ts (7.1), with the
  runtime environment block preserved on the review-start comment
- Unified command ack messages (6.3) combined with the collapsed
  runtime environment block and bot signature on /recheck replies
- Status banner and collapsible unposted findings in review bodies (6.1)
- Centralized runtime directories behind GHBOT_RUNTIME_DIR (D-13);
  webhook knowledge cache now lives under tempRootDirectory()
- Production hardening for merge races, timeouts, webhook ops;
  atomic temp-file rename for R2 cache restores kept from upstream
- Webhook parity retained: triage events gated by WEBHOOK_TRIAGE_ENABLED,
  read-only command guidance, repository knowledge injection,
  runtime environment block on webhook chat replies
- Sanitization/secret redaction centralization, error-aware retry,
  duplicate merge prevention, in-process webhook retries, /metrics
- Infra: eslint/prettier gates with CI verify workflow, docs archives

typecheck, eslint, prettier format:check, and 164 tests all pass.
2026-08-24 11:47:28 +08:00

50 lines
1.6 KiB
JavaScript

/**
* Git pre-commit 钩子(Node 版,Windows/Linux/macOS 通用)。
* 执行:磁盘上语法/完整性检查 + 生成物提交防护。
*/
"use strict";
const { execSync } = require("node:child_process");
function run(cmd) {
try {
return execSync(cmd, { encoding: "utf8", stdio: ["ignore", "pipe", "pipe"] }).trim();
} catch {
return "";
}
}
// 1) 暂存区生成物防护:graft/、.codegraph/、.code-review-graph/、dist/ 等不允许进仓库。
const staged = run("git diff --cached --name-only").split("\n").filter(Boolean);
const blockedPrefixes = ["graft/", ".codegraph/", ".code-review-graph/", "dist/", ".ghbot-tmp/"];
const blocked = staged.filter((file) =>
blockedPrefixes.some((p) => file === p.slice(0, -1) || file.startsWith(p))
);
if (blocked.length > 0) {
console.error("[pre-commit] BLOCKED:以下生成物/索引文件被暂存,已拒绝提交:");
blocked.forEach((f) => console.error(` - ${f}`));
console.error("请先 git rm --cached -r 它们。");
process.exit(1);
}
// 2) 磁盘上被修改过的 TS 文件跑一轮 tsc(增量,仅当本机装了 typescript)。
const changedTs = staged
.filter((f) => f.endsWith(".ts") || f.endsWith(".tsx"))
.map((f) => f.replace(/\\/g, "/"));
if (changedTs.length > 0) {
const tsc = run("npm run typecheck");
if (tsc && /error TS\d+/.test(tsc)) {
console.error("[pre-commit] TypeScript 类型错误,已阻止提交:");
console.error(
tsc
.split("\n")
.filter((l) => /error TS/.test(l))
.slice(0, 20)
.join("\n")
);
process.exit(1);
}
}
process.exit(0);