mirror of
https://github.com/openclaw/openclaw.git
synced 2026-08-12 21:53:00 -06:00
c70aee247e
* refactor(scripts): migrate JavaScript tools to TypeScript * fix(ci): keep changed-scope preflight zero-install * fix(ci): preserve zero-install script owners * fix(ci): complete script migration follow-through * fix(release): keep stable closeout zero-install * fix(scripts): preserve standalone execution boundaries * fix(scripts): repair standalone loader boundaries * fix(scripts): normalize gateway observation ids * fix(scripts): keep Docker packager standalone * test(scripts): preserve rebase cleanup helpers * test(sessions): use tracked temp directory
39 lines
1.2 KiB
TypeScript
39 lines
1.2 KiB
TypeScript
import { spawnSync } from "node:child_process";
|
|
|
|
// GHSA patch performs multiple sequential GitHub API reads and writes. Keep enough
|
|
// headroom for GitHub latency while preventing one stalled request from blocking
|
|
// the maintainer command indefinitely.
|
|
export const GHSA_COMMAND_TIMEOUT_MS = 60_000;
|
|
|
|
interface GhCommandParams {
|
|
spawnSyncImpl?: (
|
|
command: string,
|
|
args: string[],
|
|
options: { encoding: "utf8"; killSignal: "SIGKILL"; timeout: number },
|
|
) => {
|
|
error?: Error;
|
|
status: number | null;
|
|
stderr: string;
|
|
stdout: string;
|
|
};
|
|
timeoutMs?: number;
|
|
}
|
|
|
|
export function runGhCommand(args: string[], params: GhCommandParams = {}) {
|
|
const spawnSyncImpl: NonNullable<GhCommandParams["spawnSyncImpl"]> =
|
|
params.spawnSyncImpl ??
|
|
((command, commandArgs, options) => spawnSync(command, commandArgs, options));
|
|
const proc = spawnSyncImpl("gh", args, {
|
|
encoding: "utf8",
|
|
killSignal: "SIGKILL",
|
|
timeout: params.timeoutMs ?? GHSA_COMMAND_TIMEOUT_MS,
|
|
});
|
|
if (proc.error) {
|
|
throw proc.error;
|
|
}
|
|
if (proc.status !== 0) {
|
|
throw new Error(proc.stderr.trim() || proc.stdout.trim() || `gh ${args.join(" ")} failed`);
|
|
}
|
|
return proc.stdout;
|
|
}
|