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

fix(cli): use the singular for one repository in bulk scan prompts (#2174)

wj18312710b4db
diff --git a/sdk/typescript/src/bulk-scan-discovery.ts b/sdk/typescript/src/bulk-scan-discovery.ts
index 34259ce72..8d1c6a982 100644
--- a/sdk/typescript/src/bulk-scan-discovery.ts
+++ b/sdk/typescript/src/bulk-scan-discovery.ts
@@ -146,7 +146,7 @@ export async function runBulkScanWizard(
return null;
}
- prompt.write(`\nFound ${discovered.length} repositories.\n`);
+ prompt.write(`\nFound ${formatRepositoryCount(discovered.length)}.\n`);
const repositories = await selectGitHubRepositories(
discovered,
prompt,
@@ -166,7 +166,7 @@ export async function runBulkScanWizard(
const inputPath = join(outputDir, "repositories.csv");
await validateWizardOutput(outputDir);
prompt.write(
- `\nReady to scan ${repositories.length} repositories?\n` +
+ `\nReady to scan ${formatRepositoryCount(repositories.length)}?\n` +
`Results: ${outputDir}\nRepository list: ${inputPath}\n`,
);
if (!(await prompt.confirm("Start scanning?", false, signal))) {
@@ -225,20 +225,26 @@ async function selectGitHubOwner(
return personal;
}
+function formatRepositoryCount(count: number): string {
+ return count === 1 ? "1 repository" : `${count} repositories`;
+}
+
async function selectGitHubRepositories(
repositories: GitHubRepository[],
prompt: BulkScanPrompt,
signal?: AbortSignal,
): Promise<GitHubRepository[]> {
+ const allLabel =
+ repositories.length === 1
+ ? "All repositories"
+ : `All ${formatRepositoryCount(repositories.length)}`;
const selected = new Set<string>();
while (selected.size < repositories.length) {
const choice = await prompt.select(
"Select repositories to scan (type to filter)",
[
{
- label: selected.size
- ? `Done (${selected.size} selected)`
- : `All ${repositories.length} repositories`,
+ label: selected.size ? `Done (${selected.size} selected)` : allLabel,
value: "",
},
...repositories
diff --git a/sdk/typescript/tests-ts/bulk-scan-discovery.test.ts b/sdk/typescript/tests-ts/bulk-scan-discovery.test.ts
index acc250004..2bc766959 100644
--- a/sdk/typescript/tests-ts/bulk-scan-discovery.test.ts
+++ b/sdk/typescript/tests-ts/bulk-scan-discovery.test.ts
@@ -285,6 +285,7 @@ describe("bulk scan repository discovery", () => {
const result = await runBulkScanWizard(dependencies);
expect(result?.outputDir).toBe(join(root, "custom-results"));
+ expect(prompt.messages.join("")).toContain("Ready to scan 2 repositories?");
expect(prompt.searchOptions).toEqual([
["All 3 repositories", "acme/owl", "acme/openai", "acme/unrelated"],
["Done (1 selected)", "acme/openai", "acme/unrelated"],
@@ -387,6 +388,10 @@ describe("bulk scan repository discovery", () => {
const result = await runBulkScanWizard(dependencies);
expect(prompt.searchOptions[0]).toEqual(["acme", "personal-account"]);
+ expect(prompt.searchOptions[1]).toContain("All repositories");
+ const messages = prompt.messages.join("");
+ expect(messages).toContain("Found 1 repository.");
+ expect(messages).toContain("Ready to scan 1 repository?");
expect(
requests.find(({ path }) => path === "/graphql")?.variables?.owner,
).toBe("personal-account");