1
- // @ts -nocheck
2
1
/* eslint-disable no-console */
3
2
3
+ import chalk from 'chalk'
4
+ // @ts -ignore
5
+ import chalkTable from 'chalk-table'
4
6
import meow from 'meow'
5
7
import ora from 'ora'
6
8
7
9
import { outputFlags } from '../../flags/index.js'
8
- // import { handleApiCall, handleUnsuccessfulApiResponse } from '../../utils/api-helpers.js'
9
- import { InputError } from '../../utils/errors.js'
10
+ import { handleApiCall , handleUnsuccessfulApiResponse } from '../../utils/api-helpers.js'
10
11
import { printFlagList } from '../../utils/formatting.js'
11
- // import { getDefaultKey, setupSdk } from '../../utils/sdk.js'
12
+ import { getDefaultKey , setupSdk } from '../../utils/sdk.js'
12
13
13
14
/** @type {import('../../utils/meow-with-subcommands.js').CliSubcommand } */
14
15
export const view = {
@@ -20,7 +21,7 @@ export const view = {
20
21
if ( input ) {
21
22
const spinnerText = 'Fetching repository... \n'
22
23
const spinner = ora ( spinnerText ) . start ( )
23
- await viewRepository ( input . orgSlug , input , spinner )
24
+ await viewRepository ( input . orgSlug , input . repositoryName , spinner )
24
25
}
25
26
}
26
27
}
@@ -32,6 +33,7 @@ export const view = {
32
33
* @property {boolean } outputJson
33
34
* @property {boolean } outputMarkdown
34
35
* @property {string } orgSlug
36
+ * @property {string } repositoryName
35
37
*/
36
38
37
39
/**
@@ -68,37 +70,61 @@ function setupCommand (name, description, argv, importMeta) {
68
70
} = cli . flags
69
71
70
72
if ( ! cli . input [ 0 ] ) {
71
- throw new InputError ( `Please specify an organization slug. \n
72
- Example:
73
- socket scan list FakeOrg
74
- ` )
73
+ console . error ( `${ chalk . bgRed ( 'Input error' ) } : Please provide an organization slug \n` )
74
+ cli . showHelp ( )
75
+ return
75
76
}
76
77
77
- const orgSlug = cli . input [ 0 ] || ''
78
+ const [ orgSlug = '' , repositoryName = '' ] = cli . input
78
79
79
80
return {
80
81
outputJson,
81
82
outputMarkdown,
82
- orgSlug
83
+ orgSlug,
84
+ repositoryName
83
85
}
84
86
}
85
87
86
88
/**
87
89
* @typedef RepositoryData
88
- * @property {import('@socketsecurity/sdk').SocketSdkReturnType<'getOrgFullScanList '>["data"] } data
90
+ * @property {import('@socketsecurity/sdk').SocketSdkReturnType<'getOrgRepo '>["data"] } data
89
91
*/
90
92
91
93
/**
92
94
* @param {string } orgSlug
93
- * @param {CommandContext } input
95
+ * @param {string } repoName
94
96
* @param {import('ora').Ora } spinner
95
97
* @returns {Promise<void|RepositoryData> }
96
98
*/
97
- async function viewRepository ( orgSlug , input , spinner ) {
98
- // const socketSdk = await setupSdk(getDefaultKey())
99
- console . log ( input )
99
+ async function viewRepository ( orgSlug , repoName , spinner ) {
100
+ const socketSdk = await setupSdk ( getDefaultKey ( ) )
101
+ // @ts -ignore
102
+ const result = await handleApiCall ( socketSdk . getOrgRepo ( orgSlug , repoName ) , 'fetching repository' )
100
103
101
- // return {
102
- // // data: result.data
103
- // }
104
+ if ( ! result . success ) {
105
+ return handleUnsuccessfulApiResponse ( 'getOrgRepo' , result , spinner )
106
+ }
107
+
108
+ spinner . stop ( )
109
+
110
+ const options = {
111
+ columns : [
112
+ { field : 'id' , name : chalk . magenta ( 'ID' ) } ,
113
+ { field : 'name' , name : chalk . magenta ( 'Name' ) } ,
114
+ { field : 'visibility' , name : chalk . magenta ( 'Visibility' ) } ,
115
+ { field : 'default_branch' , name : chalk . magenta ( 'Default branch' ) } ,
116
+ { field : 'homepage' , name : chalk . magenta ( 'Homepage' ) } ,
117
+ { field : 'archived' , name : chalk . magenta ( 'Archived' ) } ,
118
+ { field : 'created_at' , name : chalk . magenta ( 'Created at' ) }
119
+ ]
120
+ }
121
+
122
+ const table = chalkTable ( options , [ result . data ] )
123
+
124
+ console . log ( table , '\n' )
125
+
126
+ return {
127
+ // @ts -ignore
128
+ data : result . data
129
+ }
104
130
}
0 commit comments