Skip to content

Commit 0b61fc4

Browse files
committed
feat(scan): add --workspace flag to scan create command
1 parent 484b1a1 commit 0b61fc4

5 files changed

Lines changed: 42 additions & 2 deletions

File tree

packages/cli/src/commands/scan/cmd-scan-create.mts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ interface ScanCreateFlags {
7575
reportLevel: REPORT_LEVEL
7676
setAsAlertsPage: boolean
7777
tmp: boolean
78+
workspace: string
7879
}
7980

8081
export const CMD_NAME = 'create'
@@ -190,6 +191,12 @@ const generalFlags: MeowFlags = {
190191
'Set the visibility (true/false) of the scan in your dashboard.',
191192
shortFlag: 't',
192193
},
194+
workspace: {
195+
type: 'string',
196+
default: '',
197+
description:
198+
'The workspace in the Socket Organization that the repository is in to associate with the full scan.',
199+
},
193200
}
194201

195202
export const cmdScanCreate = {
@@ -320,6 +327,7 @@ async function run(
320327
branch: branchName,
321328
repo: repoName,
322329
report,
330+
workspace,
323331
} = cli.flags as unknown as ScanCreateFlags
324332

325333
let { 0: orgSlug } = await determineOrgSlug(
@@ -364,6 +372,10 @@ async function run(
364372
repoName = await getRepoName(cwd)
365373
}
366374
}
375+
if (!workspace && sockJson.defaults?.scan?.create?.workspace) {
376+
workspace = sockJson.defaults.scan.create.workspace
377+
logger.info(`Using default --workspace from ${SOCKET_JSON}:`, workspace)
378+
}
367379
if (typeof report !== 'boolean') {
368380
if (sockJson.defaults?.scan?.create?.report !== undefined) {
369381
report = sockJson.defaults.scan.create.report
@@ -656,5 +668,6 @@ async function run(
656668
reportLevel,
657669
targets,
658670
tmp: Boolean(tmp),
671+
workspace: (workspace && String(workspace)) || '',
659672
})
660673
}

packages/cli/src/commands/scan/fetch-create-org-full-scan.mts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ export type FetchCreateOrgFullScanConfigs = {
1414
pullRequest: number
1515
repoName: string
1616
scanType: string | undefined
17+
workspace?: string | undefined
1718
}
1819

1920
export type FetchCreateOrgFullScanOptions = {
@@ -40,6 +41,7 @@ export async function fetchCreateOrgFullScan(
4041
pullRequest,
4142
repoName,
4243
scanType,
44+
workspace,
4345
} = { __proto__: null, ...config } as FetchCreateOrgFullScanConfigs
4446

4547
const {
@@ -71,6 +73,7 @@ export async function fetchCreateOrgFullScan(
7173
...(pullRequest ? { pull_request: String(pullRequest) } : {}),
7274
...(repoName ? { repo: repoName } : {}),
7375
...(scanType ? { scan_type: scanType } : {}),
76+
...(workspace ? { workspace } : {}),
7477
...(pendingHead !== undefined
7578
? { set_as_pending_head: Boolean(pendingHead) }
7679
: {}),

packages/cli/src/commands/scan/handle-create-new-scan.mts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ export type HandleCreateNewScanConfig = {
6868
reportLevel: REPORT_LEVEL
6969
targets: string[]
7070
tmp: boolean
71+
workspace?: string | undefined
7172
}
7273

7374
export async function handleCreateNewScan({
@@ -91,8 +92,12 @@ export async function handleCreateNewScan({
9192
reportLevel,
9293
targets,
9394
tmp,
95+
workspace,
9496
}: HandleCreateNewScanConfig): Promise<void> {
95-
debug('notice', `Creating new scan for ${orgSlug}/${repoName}`)
97+
debug(
98+
'notice',
99+
`Creating new scan for ${orgSlug}/${workspace ? `${workspace}/` : ''}${repoName}`,
100+
)
96101
debugDir('inspect', {
97102
autoManifest,
98103
branchName,
@@ -106,6 +111,7 @@ export async function handleCreateNewScan({
106111
reportLevel,
107112
targets,
108113
tmp,
114+
workspace,
109115
})
110116

111117
if (autoManifest) {
@@ -288,6 +294,7 @@ export async function handleCreateNewScan({
288294
scanType: reach.runReachabilityAnalysis
289295
? SCAN_TYPE_SOCKET_TIER1
290296
: SCAN_TYPE_SOCKET,
297+
workspace,
291298
},
292299
{
293300
cwd,

packages/cli/src/commands/scan/setup-scan-config.mts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { SOCKET_JSON } from '../../constants/paths.mts'
99
import {
1010
detectDefaultBranch,
1111
getRepoName,
12+
getRepoOwner,
1213
gitBranch,
1314
} from '../../utils/git/operations.mjs'
1415
import {
@@ -156,6 +157,21 @@ async function configureScan(
156157
delete config.repo
157158
}
158159

160+
const defaultWorkspace = await input({
161+
message:
162+
'(--workspace) The workspace in the Socket Organization that the repository is in to associate with the full scan.',
163+
default: config.workspace || (await getRepoOwner(cwd)) || '',
164+
required: false,
165+
})
166+
if (defaultWorkspace === undefined) {
167+
return canceledByUser()
168+
}
169+
if (defaultWorkspace) {
170+
config.workspace = defaultWorkspace
171+
} else {
172+
delete config.workspace
173+
}
174+
159175
const defaultBranchName = await input({
160176
message:
161177
'(--branch) What branch name (slug) should be reported to Socket for this dir?',

packages/cli/src/utils/socket/json.mts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,10 @@ export interface SocketJson {
6969
scan?: {
7070
create?: {
7171
autoManifest?: boolean | undefined
72+
branch?: string | undefined
7273
repo?: string | undefined
7374
report?: boolean | undefined
74-
branch?: string | undefined
75+
workspace?: string | undefined
7576
}
7677
github?: {
7778
all?: boolean | undefined

0 commit comments

Comments
 (0)