clawhub/scripts/install-git-hooks.mjs
Val Alexander a7547eee51
Handle package API rate limits gracefully
- Surface retryable empty states for plugin catalog and detail pages
- Preserve Retry-After metadata in package API errors
- Add staged-secret scanning and auto-installed git hooks
2026-04-05 06:15:53 -05:00

51 lines
1.2 KiB
JavaScript

#!/usr/bin/env node
import { execFileSync } from "node:child_process";
import { chmodSync, existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
import { dirname } from "node:path";
function gitPath(path) {
return execFileSync("git", ["rev-parse", "--git-path", path], { encoding: "utf8" }).trim();
}
let preCommitPath;
try {
preCommitPath = gitPath("hooks/pre-commit");
} catch {
process.exit(0);
}
const hooksDir = dirname(preCommitPath);
mkdirSync(hooksDir, { recursive: true });
const helperPath = gitPath("hooks/pre-commit-secret-scan");
const helper = `#!/bin/sh
set -eu
bun scripts/check-staged-secrets.mjs
`;
writeFileSync(helperPath, helper, "utf8");
chmodSync(helperPath, 0o755);
const hookSnippet = `
# ClawHub secret scan
"$(git rev-parse --git-path hooks/pre-commit-secret-scan)"
`;
if (!existsSync(preCommitPath)) {
writeFileSync(preCommitPath, `#!/bin/sh
set -eu${hookSnippet}
`, "utf8");
chmodSync(preCommitPath, 0o755);
process.exit(0);
}
const existing = readFileSync(preCommitPath, "utf8");
if (existing.includes("pre-commit-secret-scan")) {
process.exit(0);
}
writeFileSync(preCommitPath, `${existing.trimEnd()}${hookSnippet}
`, "utf8");
chmodSync(preCommitPath, 0o755);