From 0ee99ed21a4504775f31bd96f1f5593aa1ad19bf Mon Sep 17 00:00:00 2001 From: Peter van der Zee Date: Mon, 7 Apr 2025 16:15:20 +0200 Subject: [PATCH 1/3] Fix flags of scan create --- src/cli.ts | 4 +- src/commands/scan/cmd-scan-create.test.ts | 1 - src/commands/scan/cmd-scan-create.ts | 54 ++++++++++--------- .../scan/fetch-create-org-full-scan.ts | 29 +++++++--- src/commands/scan/handle-create-new-scan.ts | 19 +++++-- 5 files changed, 68 insertions(+), 39 deletions(-) diff --git a/src/cli.ts b/src/cli.ts index bd904ac1e..bdb805675 100755 --- a/src/cli.ts +++ b/src/cli.ts @@ -80,8 +80,8 @@ void (async () => { { aliases: { ci: { - description: 'Alias for "report create --view --strict"', - argv: ['report', 'create', '--view', '--strict'] + description: 'Alias for "scan create --report"', + argv: ['scan', 'create', '--report'] } }, argv: process.argv.slice(2), diff --git a/src/commands/scan/cmd-scan-create.test.ts b/src/commands/scan/cmd-scan-create.test.ts index a8af7a3c7..521329b36 100644 --- a/src/commands/scan/cmd-scan-create.test.ts +++ b/src/commands/scan/cmd-scan-create.test.ts @@ -63,7 +63,6 @@ describe('socket scan create', async () => { --repo Repository name --report Wait for the scan creation to complete, then basically run \`socket scan report\` on it --tmp Set the visibility (true/false) of the scan in your dashboard - --view Will wait for and return the created scan details. Use --no-view to disable. Examples $ socket scan create --repo=test-repo --branch=main FakeOrg ./package.json" diff --git a/src/commands/scan/cmd-scan-create.ts b/src/commands/scan/cmd-scan-create.ts index bf74f3f3a..073c10bd3 100644 --- a/src/commands/scan/cmd-scan-create.ts +++ b/src/commands/scan/cmd-scan-create.ts @@ -22,12 +22,6 @@ const config: CliCommandConfig = { flags: { ...commonFlags, ...outputFlags, - repo: { - type: 'string', - shortFlag: 'r', - default: 'socket-default-repository', - description: 'Repository name' - }, branch: { type: 'string', shortFlag: 'b', @@ -46,6 +40,12 @@ const config: CliCommandConfig = { default: '', description: 'Commit hash' }, + committers: { + type: 'string', + shortFlag: 'c', + default: '', + description: 'Committers' + }, cwd: { type: 'string', description: 'working directory, defaults to process.cwd()' @@ -56,34 +56,34 @@ const config: CliCommandConfig = { description: 'Set the default branch of the repository to the branch of this full-scan. Should only need to be done once, for example for the "main" or "master" branch.' }, - pendingHead: { + dryRun: { type: 'boolean', - default: true, description: - 'Designate this full-scan as the latest scan of a given branch. This must be set to have it show up in the dashboard.' + 'run input validation part of command without any concrete side effects' }, - dryRun: { + pendingHead: { type: 'boolean', + default: true, description: - 'run input validation part of command without any concrete side effects' + 'Designate this full-scan as the latest scan of a given branch. This must be set to have it show up in the dashboard.' }, pullRequest: { type: 'number', shortFlag: 'pr', description: 'Commit hash' }, - committers: { - type: 'string', - shortFlag: 'c', - default: '', - description: 'Committers' - }, readOnly: { type: 'boolean', default: false, description: 'Similar to --dry-run except it can read from remote, stops before it would create an actual report' }, + repo: { + type: 'string', + shortFlag: 'r', + default: 'socket-default-repository', + description: 'Repository name' + }, report: { type: 'boolean', default: false, @@ -96,13 +96,6 @@ const config: CliCommandConfig = { default: false, description: 'Set the visibility (true/false) of the scan in your dashboard' - }, - view: { - type: 'boolean', - shortFlag: 'v', - default: true, - description: - 'Will wait for and return the created scan details. Use --no-view to disable.' } }, // TODO: your project's "socket.yml" file's "projectIgnorePaths" @@ -162,12 +155,16 @@ async function run( const { branch: branchName = '', + commitHash, + commitMessage, + committers, cwd: cwdOverride, defaultBranch, dryRun, json, markdown, pendingHead, + pullRequest, readOnly, repo: repoName = '', report, @@ -175,11 +172,15 @@ async function run( } = cli.flags as { branch: string cwd: string + commitHash: string + commitMessage: string + committers: string defaultBranch: boolean dryRun: boolean json: boolean markdown: boolean pendingHead: boolean + pullRequest: number readOnly: boolean repo: string report: boolean @@ -274,12 +275,15 @@ async function run( await handleCreateNewScan({ branchName: branchName as string, - commitMessage: (cli.flags['commitMessage'] as string | undefined) ?? '', + commitHash: (commitHash && String(commitHash)) || '', + commitMessage: (commitMessage && String(commitMessage)) || '', + committers: (committers && String(committers)) || '', cwd, defaultBranch: Boolean(defaultBranch), orgSlug, outputKind: json ? 'json' : markdown ? 'markdown' : 'text', pendingHead: Boolean(pendingHead), + pullRequest: Number(pullRequest), readOnly: Boolean(readOnly), repoName: repoName, report, diff --git a/src/commands/scan/fetch-create-org-full-scan.ts b/src/commands/scan/fetch-create-org-full-scan.ts index c8c5c57cb..f5e3ff2e0 100644 --- a/src/commands/scan/fetch-create-org-full-scan.ts +++ b/src/commands/scan/fetch-create-org-full-scan.ts @@ -7,13 +7,25 @@ import type { SocketSdkReturnType } from '@socketsecurity/sdk' export async function fetchCreateOrgFullScan( packagePaths: string[], orgSlug: string, - repoName: string, - branchName: string, - commitMessage: string, defaultBranch: boolean, pendingHead: boolean, tmp: boolean, - cwd: string + cwd: string, + { + branchName, + commitHash, + commitMessage, + committers, + pullRequest, + repoName + }: { + branchName: string + commitHash: string + commitMessage: string + committers: string + pullRequest: number + repoName: string + } ): Promise['data'] | undefined> { const sockSdk = await setupSdk() @@ -28,10 +40,13 @@ export async function fetchCreateOrgFullScan( sockSdk.createOrgFullScan( orgSlug, { - repo: repoName, - branch: branchName, - commit_message: commitMessage, + ...(branchName ? { branch: branchName } : {}), + ...(commitHash ? { commit_hash: commitHash } : {}), + ...(commitMessage ? { commit_message: commitMessage } : {}), + ...(committers ? { committers } : {}), make_default_branch: String(defaultBranch), + ...(pullRequest ? { pull_request: String(pullRequest) } : {}), + repo: repoName || 'socket-default-repository', // mandatory, this is server default for repo set_as_pending_head: String(pendingHead), tmp: String(tmp) }, diff --git a/src/commands/scan/handle-create-new-scan.ts b/src/commands/scan/handle-create-new-scan.ts index f30c2c750..057f0d28d 100644 --- a/src/commands/scan/handle-create-new-scan.ts +++ b/src/commands/scan/handle-create-new-scan.ts @@ -9,12 +9,15 @@ import { getPackageFilesForScan } from '../../utils/path-resolve' export async function handleCreateNewScan({ branchName, + commitHash, commitMessage, + committers, cwd, defaultBranch, orgSlug, outputKind, pendingHead, + pullRequest, readOnly, repoName, report, @@ -22,11 +25,14 @@ export async function handleCreateNewScan({ tmp }: { branchName: string + commitHash: string commitMessage: string + committers: string cwd: string defaultBranch: boolean orgSlug: string pendingHead: boolean + pullRequest: number outputKind: 'json' | 'markdown' | 'text' readOnly: boolean repoName: string @@ -66,13 +72,18 @@ export async function handleCreateNewScan({ const data = await fetchCreateOrgFullScan( packagePaths, orgSlug, - repoName, - branchName, - commitMessage, defaultBranch, pendingHead, tmp, - cwd + cwd, + { + commitHash, + commitMessage, + committers, + pullRequest, + repoName, + branchName + } ) if (!data) { return From 3e79786dafec7cab4e9569a8e4b5304fca0577b1 Mon Sep 17 00:00:00 2001 From: Peter van der Zee Date: Mon, 7 Apr 2025 16:16:39 +0200 Subject: [PATCH 2/3] not yet --- src/cli.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cli.ts b/src/cli.ts index bdb805675..bd904ac1e 100755 --- a/src/cli.ts +++ b/src/cli.ts @@ -80,8 +80,8 @@ void (async () => { { aliases: { ci: { - description: 'Alias for "scan create --report"', - argv: ['scan', 'create', '--report'] + description: 'Alias for "report create --view --strict"', + argv: ['report', 'create', '--view', '--strict'] } }, argv: process.argv.slice(2), From 6efac922f938ae87d29753f601bf45b45ebb87e1 Mon Sep 17 00:00:00 2001 From: John-David Dalton Date: Mon, 7 Apr 2025 10:30:52 -0600 Subject: [PATCH 3/3] Update src/commands/scan/cmd-scan-create.ts Signed-off-by: John-David Dalton --- src/commands/scan/cmd-scan-create.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/commands/scan/cmd-scan-create.ts b/src/commands/scan/cmd-scan-create.ts index 073c10bd3..0570151f4 100644 --- a/src/commands/scan/cmd-scan-create.ts +++ b/src/commands/scan/cmd-scan-create.ts @@ -59,7 +59,7 @@ const config: CliCommandConfig = { dryRun: { type: 'boolean', description: - 'run input validation part of command without any concrete side effects' + 'Run input validation part of command without any concrete side effects' }, pendingHead: { type: 'boolean',