Skip to content

Commit 44de46e

Browse files
pvdzjdalton
andauthored
Fix flags of scan create (#423)
* Fix flags of scan create * not yet * Update src/commands/scan/cmd-scan-create.ts Signed-off-by: John-David Dalton <jdalton@users.noreply.github.com> --------- Signed-off-by: John-David Dalton <jdalton@users.noreply.github.com> Co-authored-by: John-David Dalton <jdalton@users.noreply.github.com>
1 parent 184674b commit 44de46e

File tree

4 files changed

+66
-37
lines changed

4 files changed

+66
-37
lines changed

src/commands/scan/cmd-scan-create.test.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@ describe('socket scan create', async () => {
6363
--repo Repository name
6464
--report Wait for the scan creation to complete, then basically run \`socket scan report\` on it
6565
--tmp Set the visibility (true/false) of the scan in your dashboard
66-
--view Will wait for and return the created scan details. Use --no-view to disable.
6766
6867
Examples
6968
$ socket scan create --repo=test-repo --branch=main FakeOrg ./package.json"

src/commands/scan/cmd-scan-create.ts

Lines changed: 29 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,6 @@ const config: CliCommandConfig = {
2222
flags: {
2323
...commonFlags,
2424
...outputFlags,
25-
repo: {
26-
type: 'string',
27-
shortFlag: 'r',
28-
default: 'socket-default-repository',
29-
description: 'Repository name'
30-
},
3125
branch: {
3226
type: 'string',
3327
shortFlag: 'b',
@@ -46,6 +40,12 @@ const config: CliCommandConfig = {
4640
default: '',
4741
description: 'Commit hash'
4842
},
43+
committers: {
44+
type: 'string',
45+
shortFlag: 'c',
46+
default: '',
47+
description: 'Committers'
48+
},
4949
cwd: {
5050
type: 'string',
5151
description: 'working directory, defaults to process.cwd()'
@@ -56,34 +56,34 @@ const config: CliCommandConfig = {
5656
description:
5757
'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.'
5858
},
59-
pendingHead: {
59+
dryRun: {
6060
type: 'boolean',
61-
default: true,
6261
description:
63-
'Designate this full-scan as the latest scan of a given branch. This must be set to have it show up in the dashboard.'
62+
'Run input validation part of command without any concrete side effects'
6463
},
65-
dryRun: {
64+
pendingHead: {
6665
type: 'boolean',
66+
default: true,
6767
description:
68-
'run input validation part of command without any concrete side effects'
68+
'Designate this full-scan as the latest scan of a given branch. This must be set to have it show up in the dashboard.'
6969
},
7070
pullRequest: {
7171
type: 'number',
7272
shortFlag: 'pr',
7373
description: 'Commit hash'
7474
},
75-
committers: {
76-
type: 'string',
77-
shortFlag: 'c',
78-
default: '',
79-
description: 'Committers'
80-
},
8175
readOnly: {
8276
type: 'boolean',
8377
default: false,
8478
description:
8579
'Similar to --dry-run except it can read from remote, stops before it would create an actual report'
8680
},
81+
repo: {
82+
type: 'string',
83+
shortFlag: 'r',
84+
default: 'socket-default-repository',
85+
description: 'Repository name'
86+
},
8787
report: {
8888
type: 'boolean',
8989
default: false,
@@ -96,13 +96,6 @@ const config: CliCommandConfig = {
9696
default: false,
9797
description:
9898
'Set the visibility (true/false) of the scan in your dashboard'
99-
},
100-
view: {
101-
type: 'boolean',
102-
shortFlag: 'v',
103-
default: true,
104-
description:
105-
'Will wait for and return the created scan details. Use --no-view to disable.'
10699
}
107100
},
108101
// TODO: your project's "socket.yml" file's "projectIgnorePaths"
@@ -162,24 +155,32 @@ async function run(
162155

163156
const {
164157
branch: branchName = '',
158+
commitHash,
159+
commitMessage,
160+
committers,
165161
cwd: cwdOverride,
166162
defaultBranch,
167163
dryRun,
168164
json,
169165
markdown,
170166
pendingHead,
167+
pullRequest,
171168
readOnly,
172169
repo: repoName = '',
173170
report,
174171
tmp
175172
} = cli.flags as {
176173
branch: string
177174
cwd: string
175+
commitHash: string
176+
commitMessage: string
177+
committers: string
178178
defaultBranch: boolean
179179
dryRun: boolean
180180
json: boolean
181181
markdown: boolean
182182
pendingHead: boolean
183+
pullRequest: number
183184
readOnly: boolean
184185
repo: string
185186
report: boolean
@@ -274,12 +275,15 @@ async function run(
274275

275276
await handleCreateNewScan({
276277
branchName: branchName as string,
277-
commitMessage: (cli.flags['commitMessage'] as string | undefined) ?? '',
278+
commitHash: (commitHash && String(commitHash)) || '',
279+
commitMessage: (commitMessage && String(commitMessage)) || '',
280+
committers: (committers && String(committers)) || '',
278281
cwd,
279282
defaultBranch: Boolean(defaultBranch),
280283
orgSlug,
281284
outputKind: json ? 'json' : markdown ? 'markdown' : 'text',
282285
pendingHead: Boolean(pendingHead),
286+
pullRequest: Number(pullRequest),
283287
readOnly: Boolean(readOnly),
284288
repoName: repoName,
285289
report,

src/commands/scan/fetch-create-org-full-scan.ts

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,25 @@ import type { SocketSdkReturnType } from '@socketsecurity/sdk'
77
export async function fetchCreateOrgFullScan(
88
packagePaths: string[],
99
orgSlug: string,
10-
repoName: string,
11-
branchName: string,
12-
commitMessage: string,
1310
defaultBranch: boolean,
1411
pendingHead: boolean,
1512
tmp: boolean,
16-
cwd: string
13+
cwd: string,
14+
{
15+
branchName,
16+
commitHash,
17+
commitMessage,
18+
committers,
19+
pullRequest,
20+
repoName
21+
}: {
22+
branchName: string
23+
commitHash: string
24+
commitMessage: string
25+
committers: string
26+
pullRequest: number
27+
repoName: string
28+
}
1729
): Promise<SocketSdkReturnType<'CreateOrgFullScan'>['data'] | undefined> {
1830
const sockSdk = await setupSdk()
1931

@@ -28,10 +40,13 @@ export async function fetchCreateOrgFullScan(
2840
sockSdk.createOrgFullScan(
2941
orgSlug,
3042
{
31-
repo: repoName,
32-
branch: branchName,
33-
commit_message: commitMessage,
43+
...(branchName ? { branch: branchName } : {}),
44+
...(commitHash ? { commit_hash: commitHash } : {}),
45+
...(commitMessage ? { commit_message: commitMessage } : {}),
46+
...(committers ? { committers } : {}),
3447
make_default_branch: String(defaultBranch),
48+
...(pullRequest ? { pull_request: String(pullRequest) } : {}),
49+
repo: repoName || 'socket-default-repository', // mandatory, this is server default for repo
3550
set_as_pending_head: String(pendingHead),
3651
tmp: String(tmp)
3752
},

src/commands/scan/handle-create-new-scan.ts

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,24 +9,30 @@ import { getPackageFilesForScan } from '../../utils/path-resolve'
99

1010
export async function handleCreateNewScan({
1111
branchName,
12+
commitHash,
1213
commitMessage,
14+
committers,
1315
cwd,
1416
defaultBranch,
1517
orgSlug,
1618
outputKind,
1719
pendingHead,
20+
pullRequest,
1821
readOnly,
1922
repoName,
2023
report,
2124
targets,
2225
tmp
2326
}: {
2427
branchName: string
28+
commitHash: string
2529
commitMessage: string
30+
committers: string
2631
cwd: string
2732
defaultBranch: boolean
2833
orgSlug: string
2934
pendingHead: boolean
35+
pullRequest: number
3036
outputKind: 'json' | 'markdown' | 'text'
3137
readOnly: boolean
3238
repoName: string
@@ -66,13 +72,18 @@ export async function handleCreateNewScan({
6672
const data = await fetchCreateOrgFullScan(
6773
packagePaths,
6874
orgSlug,
69-
repoName,
70-
branchName,
71-
commitMessage,
7275
defaultBranch,
7376
pendingHead,
7477
tmp,
75-
cwd
78+
cwd,
79+
{
80+
commitHash,
81+
commitMessage,
82+
committers,
83+
pullRequest,
84+
repoName,
85+
branchName
86+
}
7687
)
7788
if (!data) {
7889
return

0 commit comments

Comments
 (0)