-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathcreate-full-scan.ts
85 lines (74 loc) · 1.93 KB
/
create-full-scan.ts
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
import process from 'node:process'
import readline from 'node:readline/promises'
import open from 'open'
import colors from 'yoctocolors-cjs'
import { Spinner } from '@socketsecurity/registry/lib/spinner'
import { handleApiCall, handleUnsuccessfulApiResponse } from '../../utils/api'
import { setupSdk } from '../../utils/sdk'
export async function createFullScan({
apiToken,
branchName,
commitHash: _commitHash,
commitMessage,
committers: _committers,
cwd,
defaultBranch,
orgSlug,
packagePaths,
pendingHead,
pullRequest: _pullRequest,
repoName,
tmp
}: {
apiToken: string
orgSlug: string
repoName: string
branchName: string
committers: string
commitMessage: string
commitHash: string
pullRequest: number | undefined
defaultBranch: boolean
pendingHead: boolean
tmp: boolean
packagePaths: string[]
cwd: string
}): Promise<void> {
const spinnerText = 'Creating a scan... \n'
const spinner = new Spinner({ text: spinnerText }).start()
const socketSdk = await setupSdk(apiToken)
const result = await handleApiCall(
socketSdk.createOrgFullScan(
orgSlug,
{
repo: repoName,
branch: branchName,
commit_message: commitMessage,
make_default_branch: defaultBranch,
set_as_pending_head: pendingHead,
tmp
},
packagePaths,
cwd
),
'Creating scan'
)
if (!result.success) {
handleUnsuccessfulApiResponse('CreateOrgFullScan', result, spinner)
return
}
spinner.success('Scan created successfully')
const link = colors.underline(colors.cyan(`${result.data.html_report_url}`))
console.log(`Available at: ${link}`)
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout
})
const answer = await rl.question(
'Would you like to open it in your browser? (y/n)'
)
if (answer.toLowerCase() === 'y') {
await open(`${result.data.html_report_url}`)
}
rl.close()
}