1- // @ts -nocheck
2- /* eslint-disable */
31import chalk from 'chalk'
42import meow from 'meow'
53import ora from 'ora'
6- import fetch from 'node-fetch'
74import util from 'util'
85
96import { outputFlags } from '../../flags'
10- // import {
11- // handleApiCall,
12- // handleUnsuccessfulApiResponse
13- // } from '../../utils/api-helpers'
147import { printFlagList } from '../../utils/formatting'
158import { getDefaultKey } from '../../utils/sdk'
169
1710import type { CliSubcommand } from '../../utils/meow-with-subcommands'
1811import type { Ora } from 'ora'
1912import { AuthError } from '../../utils/errors'
13+ import { handleAPIError , queryAPI } from '../../utils/api-helpers'
2014
2115export const get : CliSubcommand = {
2216 description : 'Get a diff scan for an organization' ,
@@ -30,7 +24,7 @@ export const get: CliSubcommand = {
3024 }
3125 const spinnerText = 'Getting diff scan... \n'
3226 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 )
3428 }
3529 }
3630}
@@ -64,6 +58,7 @@ type CommandContext = {
6458 before : string
6559 after : string
6660 preview : boolean
61+ orgSlug : string
6762}
6863
6964function setupCommand (
@@ -112,39 +107,43 @@ function setupCommand(
112107 return
113108 }
114109
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+
115120 return < CommandContext > {
116121 outputJson,
117122 outputMarkdown,
118123 before,
119124 after,
120- preview
125+ preview,
126+ orgSlug
121127 }
122128}
123129
124130async function getDiffScan (
125131 before : string ,
126132 after : string ,
127133 spinner : Ora ,
128- apiKey : string
134+ apiKey : string ,
135+ orgSlug : string
129136) : 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 )
142138 const data = await response . json ( ) ;
143139
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+
148147 spinner . stop ( )
149148
150149 // before: dfc4cf0c-aefd-4081-9e4e-7385257f26e2
0 commit comments