Skip to content

Commit 7d346fb

Browse files
authored
Merge branch 'main' into soft-messages
2 parents 10d2434 + 99790f3 commit 7d346fb

File tree

9 files changed

+102
-55
lines changed

9 files changed

+102
-55
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: 35 additions & 28 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
@@ -235,11 +236,14 @@ async function run(
235236

236237
const wasBadInput = handleBadInput(
237238
{
238-
nook: true,
239-
test: orgSlug,
239+
nook: !!defaultOrgSlug,
240+
test: orgSlug && orgSlug !== '.',
240241
message: 'Org name as the first argument',
241242
pass: 'ok',
242-
fail: 'missing'
243+
fail:
244+
orgSlug === '.'
245+
? 'dot is an invalid org, most likely you forgot the org name here?'
246+
: 'missing'
243247
},
244248
{
245249
test: targets.length,
@@ -274,12 +278,15 @@ async function run(
274278

275279
await handleCreateNewScan({
276280
branchName: branchName as string,
277-
commitMessage: (cli.flags['commitMessage'] as string | undefined) ?? '',
281+
commitHash: (commitHash && String(commitHash)) || '',
282+
commitMessage: (commitMessage && String(commitMessage)) || '',
283+
committers: (committers && String(committers)) || '',
278284
cwd,
279285
defaultBranch: Boolean(defaultBranch),
280286
orgSlug,
281287
outputKind: json ? 'json' : markdown ? 'markdown' : 'text',
282288
pendingHead: Boolean(pendingHead),
289+
pullRequest: Number(pullRequest),
283290
readOnly: Boolean(readOnly),
284291
repoName: repoName,
285292
report,

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,14 @@ async function run(
6262

6363
const wasBadInput = handleBadInput(
6464
{
65-
nook: true,
66-
test: orgSlug,
65+
nook: !!defaultOrgSlug,
66+
test: orgSlug && orgSlug !== '.',
6767
message: 'Org name as the first argument',
6868
pass: 'ok',
69-
fail: 'missing'
69+
fail:
70+
orgSlug === '.'
71+
? 'dot is an invalid org, most likely you forgot the org name here?'
72+
: 'missing'
7073
},
7174
{
7275
test: scanId,

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,11 +102,14 @@ async function run(
102102

103103
const wasBadInput = handleBadInput(
104104
{
105-
nook: true,
106-
test: orgSlug,
105+
nook: !!defaultOrgSlug,
106+
test: orgSlug && orgSlug !== '.',
107107
message: 'Org name as the first argument',
108108
pass: 'ok',
109-
fail: 'missing'
109+
fail:
110+
orgSlug === '.'
111+
? 'dot is an invalid org, most likely you forgot the org name here?'
112+
: 'missing'
110113
},
111114
{
112115
nook: true,

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,14 @@ async function run(
6666

6767
const wasBadInput = handleBadInput(
6868
{
69-
nook: true,
70-
test: orgSlug,
69+
nook: !!defaultOrgSlug,
70+
test: orgSlug && orgSlug !== '.',
7171
message: 'Org name as the first argument',
7272
pass: 'ok',
73-
fail: 'missing'
73+
fail:
74+
orgSlug === '.'
75+
? 'dot is an invalid org, most likely you forgot the org name here?'
76+
: 'missing'
7477
},
7578
{
7679
test: scanId,

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,11 +105,14 @@ async function run(
105105

106106
const wasBadInput = handleBadInput(
107107
{
108-
nook: true,
109-
test: orgSlug,
108+
nook: !!defaultOrgSlug,
109+
test: orgSlug && orgSlug !== '.',
110110
message: 'Org name as the first argument',
111111
pass: 'ok',
112-
fail: 'missing'
112+
fail:
113+
orgSlug === '.'
114+
? 'dot is an invalid org, most likely you forgot the org name here?'
115+
: 'missing'
113116
},
114117
{
115118
test: scanId,

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,11 +70,14 @@ async function run(
7070

7171
const wasBadInput = handleBadInput(
7272
{
73-
nook: true,
74-
test: orgSlug,
73+
nook: !!defaultOrgSlug,
74+
test: orgSlug && orgSlug !== '.',
7575
message: 'Org name as the first argument',
7676
pass: 'ok',
77-
fail: 'missing'
77+
fail:
78+
orgSlug === '.'
79+
? 'dot is an invalid org, most likely you forgot the org name here?'
80+
: 'missing'
7881
},
7982
{
8083
test: scanId,

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)