Skip to content

Commit f2fdf8d

Browse files
committed
fix: resolve merge conflict - adopt base timeout implementation
1 parent 9d62f80 commit f2fdf8d

1 file changed

Lines changed: 25 additions & 18 deletions

File tree

‎scripts/ghsa-patch.mjs‎

Lines changed: 25 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
#!/usr/bin/env node
22
// Applies GHSA patch payloads to advisory branches.
3-
import { execFileSync, spawnSync } from "node:child_process";
3+
import { execFileSync } from "node:child_process";
44
import crypto from "node:crypto";
55
import fs from "node:fs";
66
import os from "node:os";
77
import path from "node:path";
8-
9-
const GHSA_PATCH_TIMEOUT_MS = 120_000;
8+
import { GHSA_COMMAND_TIMEOUT_MS, runGhCommand } from "./lib/ghsa-patch-subprocess.mjs";
109

1110
function usage() {
1211
console.error(
@@ -46,15 +45,19 @@ function parseArgs(argv) {
4645
}
4746

4847
function runGh(args) {
49-
const proc = spawnSync("gh", args, { encoding: "utf8" });
50-
if (proc.status !== 0) {
51-
fail(proc.stderr.trim() || proc.stdout.trim() || `gh ${args.join(" ")} failed`);
48+
try {
49+
return runGhCommand(args);
50+
} catch (error) {
51+
return fail(error instanceof Error ? error.message : String(error));
5252
}
53-
return proc.stdout;
5453
}
5554

5655
function deriveRepoFromOrigin() {
57-
const remote = execFileSync("git", ["remote", "get-url", "origin"], { encoding: "utf8", timeout: GHSA_PATCH_TIMEOUT_MS, killSignal: "SIGKILL"}).trim();
56+
const remote = execFileSync("git", ["remote", "get-url", "origin"], {
57+
encoding: "utf8",
58+
killSignal: "SIGKILL",
59+
timeout: GHSA_COMMAND_TIMEOUT_MS,
60+
}).trim();
5861
const httpsMatch = remote.match(/github\.com[/:]([^/]+)\/([^/.]+)(?:\.git)?$/);
5962
if (!httpsMatch) {
6063
fail(`Could not parse origin remote: ${remote}`);
@@ -127,16 +130,20 @@ const payload = {
127130
};
128131

129132
const patchFile = writeTempJson(payload);
130-
runGh([
131-
"api",
132-
"-H",
133-
"X-GitHub-Api-Version: 2022-11-28",
134-
"-X",
135-
"PATCH",
136-
advisoryPath,
137-
"--input",
138-
patchFile,
139-
]);
133+
try {
134+
runGh([
135+
"api",
136+
"-H",
137+
"X-GitHub-Api-Version: 2022-11-28",
138+
"-X",
139+
"PATCH",
140+
advisoryPath,
141+
"--input",
142+
patchFile,
143+
]);
144+
} finally {
145+
fs.rmSync(patchFile, { force: true });
146+
}
140147

141148
if (restoredCvss) {
142149
runGh([

0 commit comments

Comments
 (0)