1
- // @ts -nocheck
2
- /* eslint-disable */
3
1
import chalk from 'chalk'
4
2
import meow from 'meow'
5
3
import ora from 'ora'
6
- import fetch from 'node-fetch'
7
4
import util from 'util'
8
5
9
6
import { outputFlags } from '../../flags'
10
- // import {
11
- // handleApiCall,
12
- // handleUnsuccessfulApiResponse
13
- // } from '../../utils/api-helpers'
14
7
import { printFlagList } from '../../utils/formatting'
15
8
import { getDefaultKey } from '../../utils/sdk'
16
9
17
10
import type { CliSubcommand } from '../../utils/meow-with-subcommands'
18
11
import type { Ora } from 'ora'
19
12
import { AuthError } from '../../utils/errors'
13
+ import { handleAPIError , queryAPI } from '../../utils/api-helpers'
20
14
21
15
export const get : CliSubcommand = {
22
16
description : 'Get a diff scan for an organization' ,
@@ -30,7 +24,7 @@ export const get: CliSubcommand = {
30
24
}
31
25
const spinnerText = 'Getting diff scan... \n'
32
26
const spinner = ora ( spinnerText ) . start ( )
33
- await getDiffScan ( input . before , input . after , spinner , apiKey )
27
+ await getDiffScan ( input . before , input . after , spinner , apiKey , input . orgSlug )
34
28
}
35
29
}
36
30
}
@@ -64,6 +58,7 @@ type CommandContext = {
64
58
before : string
65
59
after : string
66
60
preview : boolean
61
+ orgSlug : string
67
62
}
68
63
69
64
function setupCommand (
@@ -112,39 +107,43 @@ function setupCommand(
112
107
return
113
108
}
114
109
110
+ if ( cli . input . length < 1 ) {
111
+ console . error (
112
+ `${ chalk . bgRed . white ( 'Input error' ) } : Please provide an organization slug \n`
113
+ )
114
+ cli . showHelp ( )
115
+ return
116
+ }
117
+
118
+ const [ orgSlug = '' ] = cli . input
119
+
115
120
return < CommandContext > {
116
121
outputJson,
117
122
outputMarkdown,
118
123
before,
119
124
after,
120
- preview
125
+ preview,
126
+ orgSlug
121
127
}
122
128
}
123
129
124
130
async function getDiffScan (
125
131
before : string ,
126
132
after : string ,
127
133
spinner : Ora ,
128
- apiKey : string
134
+ apiKey : string ,
135
+ orgSlug : string
129
136
) : Promise < void > {
130
- // const socketSdk = await setupSdk(apiKey)
131
- // const result = await handleApiCall(
132
- // socketSdk.getOrgFullScanList(orgSlug, input),
133
- // 'Listing scans'
134
- // )
135
-
136
- const response = await fetch ( `https://api.socket.dev/v0/orgs/SocketDev/full-scans/diff?before=${ before } &after=${ after } &preview` , {
137
- method : 'GET' ,
138
- headers : {
139
- 'Authorization' : 'Basic ' + btoa ( `${ apiKey } :${ apiKey } ` )
140
- }
141
- } ) ;
137
+ const response = await queryAPI ( `${ orgSlug } /full-scans/diff?before=${ before } &after=${ after } &preview` , apiKey )
142
138
const data = await response . json ( ) ;
143
139
144
- // if (!result.success) {
145
- // handleUnsuccessfulApiResponse('getOrgFullScanList', result, spinner)
146
- // return
147
- // }
140
+ if ( response . status !== 200 ) {
141
+ spinner . stop ( )
142
+ const err = await handleAPIError ( response . status )
143
+ console . error ( err )
144
+ return
145
+ }
146
+
148
147
spinner . stop ( )
149
148
150
149
// before: dfc4cf0c-aefd-4081-9e4e-7385257f26e2
0 commit comments