-
Notifications
You must be signed in to change notification settings - Fork 42
Expand file tree
/
Copy pathfetch-create-org-full-scan.mts
More file actions
93 lines (83 loc) · 2.68 KB
/
fetch-create-org-full-scan.mts
File metadata and controls
93 lines (83 loc) · 2.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
import fs from 'node:fs'
import path from 'node:path'
import { logger } from '@socketsecurity/registry/lib/logger'
import constants from '../../constants.mts'
import { handleApiCall } from '../../utils/api.mts'
import { setupSdk } from '../../utils/sdk.mts'
import type { CResult } from '../../types.mts'
import type { SetupSdkOptions } from '../../utils/sdk.mts'
import type { SocketSdkSuccessResult } from '@socketsecurity/sdk'
export type FetchCreateOrgFullScanConfigs = {
branchName: string
commitHash: string
commitMessage: string
committers: string
pullRequest: number
repoName: string
scanType: string | undefined
workspace?: string | undefined
}
export type FetchCreateOrgFullScanOptions = {
cwd?: string | undefined
defaultBranch?: boolean | undefined
pendingHead?: boolean | undefined
sdkOpts?: SetupSdkOptions | undefined
tmp?: boolean | undefined
}
export async function fetchCreateOrgFullScan(
packagePaths: string[],
orgSlug: string,
config: FetchCreateOrgFullScanConfigs,
options?: FetchCreateOrgFullScanOptions | undefined,
): Promise<CResult<SocketSdkSuccessResult<'CreateOrgFullScan'>['data']>> {
const {
branchName,
commitHash,
commitMessage,
committers,
pullRequest,
repoName,
scanType,
workspace,
} = { __proto__: null, ...config } as FetchCreateOrgFullScanConfigs
const {
cwd = process.cwd(),
defaultBranch,
pendingHead,
sdkOpts,
tmp,
} = { __proto__: null, ...options } as FetchCreateOrgFullScanOptions
const sockSdkCResult = await setupSdk(sdkOpts)
if (!sockSdkCResult.ok) {
return sockSdkCResult
}
const sockSdk = sockSdkCResult.data
if (constants.ENV.SOCKET_CLI_DEBUG) {
const fileInfo = await Promise.all(
packagePaths.map(async p => {
const absPath = path.resolve(process.cwd(), p)
const stat = await fs.promises.stat(absPath)
return { path: absPath, size: stat.size }
}),
)
logger.info(
`[DEBUG] ${new Date().toISOString()} Uploading full scan manifests: ${JSON.stringify(fileInfo)}`,
)
}
return await handleApiCall(
sockSdk.createOrgFullScan(orgSlug, packagePaths, cwd, {
...(branchName ? { branch: branchName } : {}),
...(commitHash ? { commit_hash: commitHash } : {}),
...(commitMessage ? { commit_message: commitMessage } : {}),
...(committers ? { committers } : {}),
make_default_branch: String(defaultBranch),
...(pullRequest ? { pull_request: String(pullRequest) } : {}),
scan_type: scanType,
repo: repoName,
...(workspace ? { workspace } : {}),
set_as_pending_head: String(pendingHead),
tmp: String(tmp),
}),
{ description: 'to create a scan' },
)
}