Skip to content

OpenAI's Codex Security CLI and TypeScript SDK for finding, validating, and fixing security vulnerabilities. npm: https://www.npmjs.com/package/@openai/codex-security

refactor(targets): share setup for Git diff scan targets (#1411)

mldangelo-oai4943ffacc836
diff --git a/sdk/typescript/src/targets.ts b/sdk/typescript/src/targets.ts
index 1d1392d5d..82e3c0908 100644
--- a/sdk/typescript/src/targets.ts
+++ b/sdk/typescript/src/targets.ts
@@ -523,29 +523,20 @@ export async function normalizeTarget(
}
await requireGitRepository(root, signal);
const base = await resolveGitRef(root, target.base, signal);
- if (target.kind === "refs") {
- const head = target.head;
- if (!isNonEmptyString(head)) {
- throw new InvalidTargetError(
- "Git diff refs must include a non-empty head ref.",
- );
- }
- return {
- kind: "refs",
- paths: [],
- base,
- head: await resolveGitRef(root, head, signal),
- baseRef: target.base,
- headRef: head,
- };
+ const kind = target.kind === "refs" ? "refs" : "working_tree";
+ const head = kind === "refs" ? target.head : "HEAD";
+ if (!isNonEmptyString(head)) {
+ throw new InvalidTargetError(
+ "Git diff refs must include a non-empty head ref.",
+ );
}
return {
- kind: "working_tree",
+ kind,
paths: [],
base,
- head: await resolveGitRef(root, "HEAD", signal),
+ head: await resolveGitRef(root, head, signal),
baseRef: target.base,
- headRef: "HEAD",
+ headRef: head,
};
}