1
- // @ts -nocheck
2
1
/* eslint-disable no-console */
3
2
4
- // import chalk from 'chalk'
3
+ import chalk from 'chalk'
5
4
import meow from 'meow'
6
5
import ora from 'ora'
7
6
8
7
import { outputFlags } from '../../flags/index.js'
9
- // import { handleApiCall, handleUnsuccessfulApiResponse } from '../../utils/api-helpers.js'
10
- import { InputError } from '../../utils/errors .js'
8
+ import { handleApiCall , handleUnsuccessfulApiResponse } from '../../utils/api-helpers.js'
9
+ import { prepareFlags } from '../../utils/flags .js'
11
10
import { printFlagList } from '../../utils/formatting.js'
12
- // import { getDefaultKey, setupSdk } from '../../utils/sdk.js'
11
+ import { getDefaultKey , setupSdk } from '../../utils/sdk.js'
13
12
14
13
/** @type {import('../../utils/meow-with-subcommands.js').CliSubcommand } */
15
14
export const update = {
@@ -26,13 +25,51 @@ export const update = {
26
25
}
27
26
}
28
27
28
+ const repositoryUpdateFlags = prepareFlags ( {
29
+ repoName : {
30
+ type : 'string' ,
31
+ shortFlag : 'n' ,
32
+ default : '' ,
33
+ description : 'Repository name' ,
34
+ } ,
35
+ repoDescription : {
36
+ type : 'string' ,
37
+ shortFlag : 'd' ,
38
+ default : '' ,
39
+ description : 'Repository description' ,
40
+ } ,
41
+ homepage : {
42
+ type : 'string' ,
43
+ shortFlag : 'h' ,
44
+ default : '' ,
45
+ description : 'Repository url' ,
46
+ } ,
47
+ defaultBranch : {
48
+ type : 'string' ,
49
+ shortFlag : 'b' ,
50
+ default : 'main' ,
51
+ description : 'Repository default branch' ,
52
+ } ,
53
+ visibility : {
54
+ type : 'string' ,
55
+ shortFlag : 'v' ,
56
+ default : 'private' ,
57
+ description : 'Repository visibility (Default Private)' ,
58
+ }
59
+ } )
60
+
29
61
// Internal functions
30
62
31
63
/**
32
64
* @typedef CommandContext
33
65
* @property {boolean } outputJson
34
66
* @property {boolean } outputMarkdown
35
67
* @property {string } orgSlug
68
+ * @property {string } name
69
+ * @property {string } description
70
+ * @property {string } homepage
71
+ * @property {string } default_branch
72
+ * @property {string } visibility
36
73
*/
37
74
38
75
/**
@@ -44,7 +81,8 @@ export const update = {
44
81
*/
45
82
function setupCommand ( name , description , argv , importMeta ) {
46
83
const flags = {
47
- ...outputFlags
84
+ ...outputFlags ,
85
+ ...repositoryUpdateFlags
48
86
}
49
87
50
88
const cli = meow ( `
@@ -65,28 +103,43 @@ function setupCommand (name, description, argv, importMeta) {
65
103
66
104
const {
67
105
json : outputJson ,
68
- markdown : outputMarkdown
106
+ markdown : outputMarkdown ,
107
+ repoName,
108
+ repoDescription,
109
+ homepage,
110
+ defaultBranch,
111
+ visibility
69
112
} = cli . flags
70
113
71
- if ( ! cli . input [ 0 ] ) {
72
- throw new InputError ( `Please specify an organization slug. \n
73
- Example:
74
- socket scan list FakeOrg
75
- ` )
114
+ const [ orgSlug = '' ] = cli . input
115
+
116
+ if ( ! orgSlug ) {
117
+ console . error ( `${ chalk . bgRed ( 'Input error' ) } : Please provide an organization slug and repository name \n` )
118
+ cli . showHelp ( )
119
+ return
76
120
}
77
121
78
- const orgSlug = cli . input [ 0 ] || ''
122
+ if ( ! repoName ) {
123
+ console . error ( `${ chalk . bgRed ( 'Input error' ) } : Repository name is required. \n` )
124
+ cli . showHelp ( )
125
+ return
126
+ }
79
127
80
128
return {
81
129
outputJson,
82
130
outputMarkdown,
83
- orgSlug
131
+ orgSlug,
132
+ name : repoName ,
133
+ description : repoDescription ,
134
+ homepage,
135
+ default_branch : defaultBranch ,
136
+ visibility
84
137
}
85
138
}
86
139
87
140
/**
88
141
* @typedef RepositoryData
89
- * @property {import('@socketsecurity/sdk').SocketSdkReturnType<'getOrgFullScanList '>["data"] } data
142
+ * @property {import('@socketsecurity/sdk').SocketSdkReturnType<'updateOrgRepo '>["data"] } data
90
143
*/
91
144
92
145
/**
@@ -96,10 +149,19 @@ socket scan list FakeOrg
96
149
* @returns {Promise<void|RepositoryData> }
97
150
*/
98
151
async function updateRepository ( orgSlug , input , spinner ) {
99
- // const socketSdk = await setupSdk(getDefaultKey())
100
- console . log ( input )
152
+ const socketSdk = await setupSdk ( getDefaultKey ( ) )
153
+ // @ts -ignore
154
+ const result = await handleApiCall ( socketSdk . updateOrgRepo ( orgSlug , input . name , input ) , 'listing repositories' )
155
+
156
+ if ( ! result . success ) {
157
+ return handleUnsuccessfulApiResponse ( 'updateOrgRepo' , result , spinner )
158
+ }
159
+
160
+ spinner . stop ( )
161
+
162
+ console . log ( '\n✅ Repository updated successfully \n' )
101
163
102
- // return {
103
- // // data: result.data
104
- // }
164
+ return {
165
+ data : result . data
166
+ }
105
167
}
0 commit comments