diff --git a/src/commands/scan/cmd-scan-create.mts b/src/commands/scan/cmd-scan-create.mts index 2251438bc..fca4d5624 100644 --- a/src/commands/scan/cmd-scan-create.mts +++ b/src/commands/scan/cmd-scan-create.mts @@ -122,6 +122,12 @@ const generalFlags: MeowFlags = { shortFlag: 'r', description: 'Repository name', }, + workspace: { + type: 'string', + default: '', + description: + 'The workspace in the Socket Organization that the repository is in to associate with the full scan.', + }, report: { type: 'boolean', description: @@ -304,11 +310,13 @@ async function run( branch: branchName, repo: repoName, report, + workspace, } = cli.flags as { autoManifest?: boolean | undefined branch: string repo: string report?: boolean | undefined + workspace: string } let { 0: orgSlug } = await determineOrgSlug( @@ -353,6 +361,10 @@ async function run( repoName = await getRepoName(cwd) } } + if (!workspace && sockJson.defaults?.scan?.create?.workspace) { + workspace = sockJson.defaults.scan.create.workspace + logger.info(`Using default --workspace from ${SOCKET_JSON}:`, workspace) + } if (typeof report !== 'boolean') { if (sockJson.defaults?.scan?.create?.report !== undefined) { report = sockJson.defaults.scan.create.report @@ -595,5 +607,6 @@ async function run( reportLevel, targets, tmp: Boolean(tmp), + workspace: (workspace && String(workspace)) || '', }) } diff --git a/src/commands/scan/cmd-scan-create.test.mts b/src/commands/scan/cmd-scan-create.test.mts index 46e82ce7e..aeffc1e14 100644 --- a/src/commands/scan/cmd-scan-create.test.mts +++ b/src/commands/scan/cmd-scan-create.test.mts @@ -52,6 +52,7 @@ describe('socket scan create', async () => { --report-level Which policy level alerts should be reported (default 'error') --set-as-alerts-page When true and if this is the "default branch" then this Scan will be the one reflected on your alerts page. See help for details. Defaults to true. --tmp Set the visibility (true/false) of the scan in your dashboard. + --workspace The workspace in the Socket Organization that the repository is in to associate with the full scan. Reachability Options (when --reach is used) --reach-analysis-memory-limit The maximum memory in MB to use for the reachability analysis. The default is 8192MB. diff --git a/src/commands/scan/fetch-create-org-full-scan.mts b/src/commands/scan/fetch-create-org-full-scan.mts index bb04bdafe..34e5aadf9 100644 --- a/src/commands/scan/fetch-create-org-full-scan.mts +++ b/src/commands/scan/fetch-create-org-full-scan.mts @@ -19,6 +19,7 @@ export type FetchCreateOrgFullScanConfigs = { pullRequest: number repoName: string scanType: string | undefined + workspace?: string | undefined } export type FetchCreateOrgFullScanOptions = { @@ -43,6 +44,7 @@ export async function fetchCreateOrgFullScan( pullRequest, repoName, scanType, + workspace, } = { __proto__: null, ...config } as FetchCreateOrgFullScanConfigs const { @@ -82,6 +84,7 @@ export async function fetchCreateOrgFullScan( ...(pullRequest ? { pull_request: String(pullRequest) } : {}), scan_type: scanType, repo: repoName, + ...(workspace ? { workspace } : {}), set_as_pending_head: String(pendingHead), tmp: String(tmp), }), diff --git a/src/commands/scan/handle-create-new-scan.mts b/src/commands/scan/handle-create-new-scan.mts index ae932653b..1203906f0 100644 --- a/src/commands/scan/handle-create-new-scan.mts +++ b/src/commands/scan/handle-create-new-scan.mts @@ -84,6 +84,7 @@ export type HandleCreateNewScanConfig = { reportLevel: REPORT_LEVEL targets: string[] tmp: boolean + workspace?: string | undefined } export async function handleCreateNewScan({ @@ -106,8 +107,12 @@ export async function handleCreateNewScan({ reportLevel, targets, tmp, + workspace, }: HandleCreateNewScanConfig): Promise { - debugFn('notice', `Creating new scan for ${orgSlug}/${repoName}`) + debugFn( + 'notice', + `Creating new scan for ${orgSlug}/${workspace ? `${workspace}/` : ''}${repoName}`, + ) debugDir('inspect', { autoManifest, branchName, @@ -121,6 +126,7 @@ export async function handleCreateNewScan({ reportLevel, targets, tmp, + workspace, }) if (autoManifest) { @@ -257,6 +263,7 @@ export async function handleCreateNewScan({ scanType: reach.runReachabilityAnalysis ? constants.SCAN_TYPE_SOCKET_TIER1 : constants.SCAN_TYPE_SOCKET, + workspace, }, { cwd, diff --git a/src/commands/scan/setup-scan-config.mts b/src/commands/scan/setup-scan-config.mts index 5d2b21b46..76390c66b 100644 --- a/src/commands/scan/setup-scan-config.mts +++ b/src/commands/scan/setup-scan-config.mts @@ -8,6 +8,7 @@ import constants, { SOCKET_JSON } from '../../constants.mts' import { detectDefaultBranch, getRepoName, + getRepoOwner, gitBranch, } from '../../utils/git.mts' import { @@ -154,6 +155,22 @@ async function configureScan( delete config.repo } + const defaultWorkspace = await input({ + message: + '(--workspace) The workspace in the Socket Organization that the repository is in to associate with the full scan.', + default: config.workspace || (await getRepoOwner(cwd)) || '', + required: false, + // validate: async string => bool + }) + if (defaultWorkspace === undefined) { + return canceledByUser() + } + if (defaultWorkspace) { + config.workspace = defaultWorkspace + } else { + delete config.workspace + } + const defaultBranchName = await input({ message: '(--branch) What branch name (slug) should be reported to Socket for this dir?', diff --git a/src/utils/socket-json.mts b/src/utils/socket-json.mts index db92b8e08..c3bde9e87 100644 --- a/src/utils/socket-json.mts +++ b/src/utils/socket-json.mts @@ -71,6 +71,7 @@ export interface SocketJson { repo?: string | undefined report?: boolean | undefined branch?: string | undefined + workspace?: string | undefined } github?: { all?: boolean | undefined