Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion src/commands/scan/cmd-scan-create.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
54 changes: 29 additions & 25 deletions src/commands/scan/cmd-scan-create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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()'
Expand All @@ -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,
Expand All @@ -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"
Expand Down Expand Up @@ -162,24 +155,32 @@ async function run(

const {
branch: branchName = '',
commitHash,
commitMessage,
committers,
cwd: cwdOverride,
defaultBranch,
dryRun,
json,
markdown,
pendingHead,
pullRequest,
readOnly,
repo: repoName = '',
report,
tmp
} = 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
Expand Down Expand Up @@ -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,
Expand Down
29 changes: 22 additions & 7 deletions src/commands/scan/fetch-create-org-full-scan.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<SocketSdkReturnType<'CreateOrgFullScan'>['data'] | undefined> {
const sockSdk = await setupSdk()

Expand All @@ -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)
},
Expand Down
19 changes: 15 additions & 4 deletions src/commands/scan/handle-create-new-scan.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,30 @@ import { getPackageFilesForScan } from '../../utils/path-resolve'

export async function handleCreateNewScan({
branchName,
commitHash,
commitMessage,
committers,
cwd,
defaultBranch,
orgSlug,
outputKind,
pendingHead,
pullRequest,
readOnly,
repoName,
report,
targets,
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
Expand Down Expand Up @@ -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
Expand Down