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'
11
9
import { prepareFlags } from '../../utils/flags.js'
12
10
import { printFlagList } from '../../utils/formatting.js'
13
- // import { getDefaultKey, setupSdk } from '../../utils/sdk.js'
11
+ import { getDefaultKey , setupSdk } from '../../utils/sdk.js'
14
12
15
13
/** @type {import('../../utils/meow-with-subcommands.js').CliSubcommand } */
16
14
export const create = {
@@ -27,42 +25,36 @@ export const create = {
27
25
}
28
26
}
29
27
30
- const listFullScanFlags = prepareFlags ( {
31
- sort : {
28
+ const repositoryCreationFlags = prepareFlags ( {
29
+ repoName : {
32
30
type : 'string' ,
33
- shortFlag : 's ' ,
34
- default : 'created_at ' ,
35
- description : 'Sorting option (` name` or `created_at`) - default is `created_at` ' ,
31
+ shortFlag : 'n ' ,
32
+ default : '' ,
33
+ description : 'Repository name' ,
36
34
} ,
37
- direction : {
35
+ repoDescription : {
38
36
type : 'string' ,
39
37
shortFlag : 'd' ,
40
- default : 'desc' ,
41
- description : 'Direction option (`desc` or `asc`) - Default is `desc`' ,
42
- } ,
43
- perPage : {
44
- type : 'number' ,
45
- shortFlag : 'pp' ,
46
- default : 30 ,
47
- description : 'Results per page - Default is 30' ,
48
- } ,
49
- page : {
50
- type : 'number' ,
51
- shortFlag : 'p' ,
52
- default : 1 ,
53
- description : 'Page number - Default is 1' ,
38
+ default : '' ,
39
+ description : 'Repository description' ,
54
40
} ,
55
- fromTime : {
41
+ homepage : {
56
42
type : 'string' ,
57
- shortFlag : 'f ' ,
43
+ shortFlag : 'h ' ,
58
44
default : '' ,
59
- description : 'From time - as a unix timestamp ' ,
45
+ description : 'Repository url ' ,
60
46
} ,
61
- untilTime : {
47
+ defaultBranch : {
62
48
type : 'string' ,
63
- shortFlag : 'u' ,
64
- default : '' ,
65
- description : 'Until time - as a unix timestamp' ,
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)' ,
66
58
}
67
59
} )
68
60
@@ -73,12 +65,11 @@ const listFullScanFlags = prepareFlags({
73
65
* @property {boolean } outputJson
74
66
* @property {boolean } outputMarkdown
75
67
* @property {string } orgSlug
76
- * @property {string } sort
77
- * @property {string } direction
78
- * @property {number } perPage
79
- * @property {number } page
80
- * @property {string } fromTime
81
- * @property {string } untilTime
68
+ * @property {string } name
69
+ * @property {string } description
70
+ * @property {string } homepage
71
+ * @property {string } default_branch
72
+ * @property {string } visibility
82
73
*/
83
74
84
75
/**
@@ -91,7 +82,7 @@ const listFullScanFlags = prepareFlags({
91
82
function setupCommand ( name , description , argv , importMeta ) {
92
83
const flags = {
93
84
...outputFlags ,
94
- ...listFullScanFlags
85
+ ...repositoryCreationFlags
95
86
}
96
87
97
88
const cli = meow ( `
@@ -102,7 +93,7 @@ function setupCommand (name, description, argv, importMeta) {
102
93
${ printFlagList ( flags , 6 ) }
103
94
104
95
Examples
105
- $ ${ name } FakeOrg
96
+ $ ${ name } FakeOrg --repoName=test-repo
106
97
` , {
107
98
argv,
108
99
description,
@@ -113,52 +104,64 @@ function setupCommand (name, description, argv, importMeta) {
113
104
const {
114
105
json : outputJson ,
115
106
markdown : outputMarkdown ,
116
- sort,
117
- direction,
118
- perPage,
119
- page,
120
- fromTime,
121
- untilTime
107
+ repoName,
108
+ repoDescription,
109
+ homepage,
110
+ defaultBranch,
111
+ visibility
122
112
} = cli . flags
123
113
124
- if ( ! cli . input [ 0 ] ) {
125
- throw new InputError ( `Please specify an organization slug. \n
126
- Example:
127
- socket scan list FakeOrg
128
- ` )
114
+ const [ orgSlug = '' ] = cli . input
115
+
116
+ if ( ! orgSlug ) {
117
+ console . error ( `${ chalk . bgRed ( 'Input error' ) } : Please provide an organization slug \n` )
118
+ cli . showHelp ( )
119
+ return
129
120
}
130
121
131
- 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
+ }
132
127
133
128
return {
134
129
outputJson,
135
130
outputMarkdown,
136
131
orgSlug,
137
- sort,
138
- direction,
139
- perPage,
140
- page,
141
- fromTime,
142
- untilTime
132
+ name : repoName ,
133
+ description : repoDescription ,
134
+ homepage,
135
+ default_branch : defaultBranch ,
136
+ visibility
143
137
}
144
138
}
145
139
146
140
/**
147
- * @typedef FullScansData
148
- * @property {import('@socketsecurity/sdk').SocketSdkReturnType<'getOrgFullScanList '>["data"] } data
141
+ * @typedef RepositoryData
142
+ * @property {import('@socketsecurity/sdk').SocketSdkReturnType<'createOrgRepo '>["data"] } data
149
143
*/
150
144
151
145
/**
152
146
* @param {string } orgSlug
153
147
* @param {CommandContext } input
154
148
* @param {import('ora').Ora } spinner
155
- * @returns {Promise<void|FullScansData > }
149
+ * @returns {Promise<void|RepositoryData > }
156
150
*/
157
151
async function createRepo ( orgSlug , input , spinner ) {
158
- // const socketSdk = await setupSdk(getDefaultKey())
159
- console . log ( input )
152
+ const socketSdk = await setupSdk ( getDefaultKey ( ) )
153
+ // @ts -ignore
154
+ const result = await handleApiCall ( socketSdk . createOrgRepo ( orgSlug , input ) , 'listing repositories' )
155
+
156
+ if ( ! result . success ) {
157
+ return handleUnsuccessfulApiResponse ( 'createOrgRepo' , result , spinner )
158
+ }
159
+
160
+ spinner . stop ( )
160
161
161
- // return {
162
- // // data: result.data
163
- // }
162
+ console . log ( '\n✅ Repository created successfully \n' )
163
+
164
+ return {
165
+ data : result . data
166
+ }
164
167
}
0 commit comments