@socketsecurity/cli 0.11.0 → 0.11.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +22 -22
- package/bin/npm +2 -0
- package/bin/npx +2 -0
- package/dist/cli.d.ts +3 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +3419 -0
- package/dist/errors.d.ts +7 -0
- package/dist/link.d.ts +2 -0
- package/dist/link.js +45 -0
- package/dist/npm-cli.d.ts +2 -0
- package/dist/npm-cli.js +84 -0
- package/dist/npm-injection.d.ts +1 -0
- package/dist/npm-injection.js +913 -0
- package/dist/npm-injection2.d.ts +25 -0
- package/dist/npm-injection2.js +899 -0
- package/dist/npx-cli.d.ts +2 -0
- package/dist/npx-cli.js +60 -0
- package/dist/path-resolve.d.ts +12 -0
- package/dist/path-resolve.js +139 -0
- package/dist/sdk.d.ts +27 -0
- package/dist/sdk.js +224 -0
- package/dist/settings.d.ts +9 -0
- package/dist/type-helpers.d.ts +3 -0
- package/dist/vendor.js +25421 -0
- package/package.json +105 -52
- package/{lib/shadow/translations.json → translations.json} +20 -20
- package/cli.js +0 -72
- package/lib/commands/audit-log/index.js +0 -162
- package/lib/commands/cdxgen/index.js +0 -211
- package/lib/commands/dependencies/index.js +0 -150
- package/lib/commands/index.js +0 -15
- package/lib/commands/info/index.js +0 -287
- package/lib/commands/login/index.js +0 -170
- package/lib/commands/logout/index.js +0 -35
- package/lib/commands/npm/index.js +0 -27
- package/lib/commands/npx/index.js +0 -22
- package/lib/commands/organizations/index.js +0 -81
- package/lib/commands/raw-npm/index.js +0 -59
- package/lib/commands/raw-npx/index.js +0 -59
- package/lib/commands/report/create.js +0 -251
- package/lib/commands/report/index.js +0 -24
- package/lib/commands/report/view.js +0 -176
- package/lib/commands/repos/create.js +0 -166
- package/lib/commands/repos/delete.js +0 -93
- package/lib/commands/repos/index.js +0 -30
- package/lib/commands/repos/list.js +0 -170
- package/lib/commands/repos/update.js +0 -166
- package/lib/commands/repos/view.js +0 -128
- package/lib/commands/scan/create.js +0 -245
- package/lib/commands/scan/delete.js +0 -112
- package/lib/commands/scan/index.js +0 -30
- package/lib/commands/scan/list.js +0 -192
- package/lib/commands/scan/metadata.js +0 -113
- package/lib/commands/scan/stream.js +0 -115
- package/lib/commands/wrapper/index.js +0 -199
- package/lib/flags/command.js +0 -14
- package/lib/flags/index.js +0 -3
- package/lib/flags/output.js +0 -16
- package/lib/flags/validation.js +0 -14
- package/lib/shadow/bin/npm +0 -2
- package/lib/shadow/bin/npx +0 -2
- package/lib/shadow/link.cjs +0 -50
- package/lib/shadow/npm-cli.cjs +0 -27
- package/lib/shadow/npm-injection.cjs +0 -649
- package/lib/shadow/npx-cli.cjs +0 -27
- package/lib/shadow/package.json +0 -3
- package/lib/shadow/tty-server.cjs +0 -222
- package/lib/shadow/update-notifier.mjs +0 -3
- package/lib/utils/api-helpers.js +0 -42
- package/lib/utils/chalk-markdown.js +0 -125
- package/lib/utils/errors.js +0 -14
- package/lib/utils/flags.js +0 -27
- package/lib/utils/format-issues.js +0 -99
- package/lib/utils/formatting.js +0 -47
- package/lib/utils/issue-rules.cjs +0 -180
- package/lib/utils/meow-with-subcommands.js +0 -87
- package/lib/utils/misc.js +0 -61
- package/lib/utils/path-resolve.js +0 -204
- package/lib/utils/sdk.js +0 -99
- package/lib/utils/settings.js +0 -69
- package/lib/utils/type-helpers.cjs +0 -13
- package/lib/utils/update-notifier.js +0 -18
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import { create } from './create.js'
|
|
2
|
-
import { view } from './view.js'
|
|
3
|
-
import { meowWithSubcommands } from '../../utils/meow-with-subcommands.js'
|
|
4
|
-
|
|
5
|
-
const description = 'Project report related commands'
|
|
6
|
-
|
|
7
|
-
/** @type {import('../../utils/meow-with-subcommands.js').CliSubcommand} */
|
|
8
|
-
export const report = {
|
|
9
|
-
description,
|
|
10
|
-
run: async (argv, importMeta, { parentName }) => {
|
|
11
|
-
await meowWithSubcommands(
|
|
12
|
-
{
|
|
13
|
-
create,
|
|
14
|
-
view,
|
|
15
|
-
},
|
|
16
|
-
{
|
|
17
|
-
argv,
|
|
18
|
-
description,
|
|
19
|
-
importMeta,
|
|
20
|
-
name: parentName + ' report',
|
|
21
|
-
}
|
|
22
|
-
)
|
|
23
|
-
}
|
|
24
|
-
}
|
|
@@ -1,176 +0,0 @@
|
|
|
1
|
-
/* eslint-disable no-console */
|
|
2
|
-
|
|
3
|
-
import chalk from 'chalk'
|
|
4
|
-
import meow from 'meow'
|
|
5
|
-
import ora from 'ora'
|
|
6
|
-
import { ErrorWithCause } from 'pony-cause'
|
|
7
|
-
|
|
8
|
-
import { outputFlags, validationFlags } from '../../flags/index.js'
|
|
9
|
-
import { handleApiCall, handleUnsuccessfulApiResponse } from '../../utils/api-helpers.js'
|
|
10
|
-
import { ChalkOrMarkdown } from '../../utils/chalk-markdown.js'
|
|
11
|
-
import { InputError } from '../../utils/errors.js'
|
|
12
|
-
import { getSeverityCount, formatSeverityCount } from '../../utils/format-issues.js'
|
|
13
|
-
import { printFlagList } from '../../utils/formatting.js'
|
|
14
|
-
import { setupSdk } from '../../utils/sdk.js'
|
|
15
|
-
|
|
16
|
-
/** @type {import('../../utils/meow-with-subcommands.js').CliSubcommand} */
|
|
17
|
-
export const view = {
|
|
18
|
-
description: 'View a project report',
|
|
19
|
-
async run (argv, importMeta, { parentName }) {
|
|
20
|
-
const name = parentName + ' view'
|
|
21
|
-
|
|
22
|
-
const input = setupCommand(name, view.description, argv, importMeta)
|
|
23
|
-
const result = input && await fetchReportData(input.reportId, input)
|
|
24
|
-
|
|
25
|
-
if (result) {
|
|
26
|
-
formatReportDataOutput(result, { name, ...input })
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
// Internal functions
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* @typedef CommandContext
|
|
35
|
-
* @property {boolean} includeAllIssues
|
|
36
|
-
* @property {boolean} outputJson
|
|
37
|
-
* @property {boolean} outputMarkdown
|
|
38
|
-
* @property {string} reportId
|
|
39
|
-
* @property {boolean} strict
|
|
40
|
-
*/
|
|
41
|
-
|
|
42
|
-
/**
|
|
43
|
-
* @param {string} name
|
|
44
|
-
* @param {string} description
|
|
45
|
-
* @param {readonly string[]} argv
|
|
46
|
-
* @param {ImportMeta} importMeta
|
|
47
|
-
* @returns {void|CommandContext}
|
|
48
|
-
*/
|
|
49
|
-
function setupCommand (name, description, argv, importMeta) {
|
|
50
|
-
const flags = {
|
|
51
|
-
...outputFlags,
|
|
52
|
-
...validationFlags,
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
const cli = meow(`
|
|
56
|
-
Usage
|
|
57
|
-
$ ${name} <report-identifier>
|
|
58
|
-
|
|
59
|
-
Options
|
|
60
|
-
${printFlagList(flags, 6)}
|
|
61
|
-
|
|
62
|
-
Examples
|
|
63
|
-
$ ${name} QXU8PmK7LfH608RAwfIKdbcHgwEd_ZeWJ9QEGv05FJUQ
|
|
64
|
-
`, {
|
|
65
|
-
argv,
|
|
66
|
-
description,
|
|
67
|
-
importMeta,
|
|
68
|
-
flags,
|
|
69
|
-
})
|
|
70
|
-
|
|
71
|
-
// Extract the input
|
|
72
|
-
|
|
73
|
-
const {
|
|
74
|
-
all: includeAllIssues,
|
|
75
|
-
json: outputJson,
|
|
76
|
-
markdown: outputMarkdown,
|
|
77
|
-
strict,
|
|
78
|
-
} = cli.flags
|
|
79
|
-
|
|
80
|
-
const [reportId, ...extraInput] = cli.input
|
|
81
|
-
|
|
82
|
-
if (!reportId) {
|
|
83
|
-
cli.showHelp()
|
|
84
|
-
return
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
// Validate the input
|
|
88
|
-
|
|
89
|
-
if (extraInput.length) {
|
|
90
|
-
throw new InputError(`Can only handle a single report ID at a time, but got ${cli.input.length} report ID:s: ${cli.input.join(', ')}`)
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
return {
|
|
94
|
-
includeAllIssues,
|
|
95
|
-
outputJson,
|
|
96
|
-
outputMarkdown,
|
|
97
|
-
reportId,
|
|
98
|
-
strict,
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
/**
|
|
103
|
-
* @typedef {import('@socketsecurity/sdk').SocketSdkReturnType<'getReport'>["data"]} ReportData
|
|
104
|
-
*/
|
|
105
|
-
|
|
106
|
-
const MAX_TIMEOUT_RETRY = 5
|
|
107
|
-
|
|
108
|
-
/**
|
|
109
|
-
* @param {string} reportId
|
|
110
|
-
* @param {Pick<CommandContext, 'includeAllIssues' | 'strict'>} context
|
|
111
|
-
* @returns {Promise<void|ReportData>}
|
|
112
|
-
*/
|
|
113
|
-
export async function fetchReportData (reportId, { includeAllIssues, strict }) {
|
|
114
|
-
// Do the API call
|
|
115
|
-
|
|
116
|
-
const socketSdk = await setupSdk()
|
|
117
|
-
const spinner = ora(`Fetching report with ID ${reportId} (this could take a while)`).start()
|
|
118
|
-
/** @type {import('@socketsecurity/sdk').SocketSdkResultType<'getReport'> | undefined} */
|
|
119
|
-
let result
|
|
120
|
-
for (let retry = 1; !result; ++retry) {
|
|
121
|
-
try {
|
|
122
|
-
result = await handleApiCall(socketSdk.getReport(reportId), 'fetching report')
|
|
123
|
-
} catch (err) {
|
|
124
|
-
if (
|
|
125
|
-
retry >= MAX_TIMEOUT_RETRY ||
|
|
126
|
-
!(err instanceof ErrorWithCause) ||
|
|
127
|
-
err.cause?.cause?.response?.statusCode !== 524
|
|
128
|
-
) {
|
|
129
|
-
throw err
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
if (result.success === false) {
|
|
135
|
-
return handleUnsuccessfulApiResponse('getReport', result, spinner)
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
// Conclude the status of the API call
|
|
139
|
-
|
|
140
|
-
if (strict) {
|
|
141
|
-
if (result.data.healthy) {
|
|
142
|
-
spinner.succeed('Report result is healthy and great!')
|
|
143
|
-
} else {
|
|
144
|
-
spinner.fail('Report result deemed unhealthy for project')
|
|
145
|
-
}
|
|
146
|
-
} else if (result.data.healthy === false) {
|
|
147
|
-
const severityCount = getSeverityCount(result.data.issues, includeAllIssues ? undefined : 'high')
|
|
148
|
-
const issueSummary = formatSeverityCount(severityCount)
|
|
149
|
-
spinner.succeed(`Report has these issues: ${issueSummary}`)
|
|
150
|
-
} else {
|
|
151
|
-
spinner.succeed('Report has no issues')
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
return result.data
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
/**
|
|
158
|
-
* @param {ReportData} data
|
|
159
|
-
* @param {{ name: string } & CommandContext} context
|
|
160
|
-
* @returns {void}
|
|
161
|
-
*/
|
|
162
|
-
export function formatReportDataOutput (data, { name, outputJson, outputMarkdown, reportId, strict }) {
|
|
163
|
-
if (outputJson) {
|
|
164
|
-
console.log(JSON.stringify(data, undefined, 2))
|
|
165
|
-
} else {
|
|
166
|
-
const format = new ChalkOrMarkdown(!!outputMarkdown)
|
|
167
|
-
console.log('\nDetailed info on socket.dev: ' + format.hyperlink(reportId, data.url, { fallbackToUrl: true }))
|
|
168
|
-
if (!outputMarkdown) {
|
|
169
|
-
console.log(chalk.dim('\nOr rerun', chalk.italic(name), 'using the', chalk.italic('--json'), 'flag to get full JSON output'))
|
|
170
|
-
}
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
if (strict && data.healthy === false) {
|
|
174
|
-
process.exit(1)
|
|
175
|
-
}
|
|
176
|
-
}
|
|
@@ -1,166 +0,0 @@
|
|
|
1
|
-
/* eslint-disable no-console */
|
|
2
|
-
|
|
3
|
-
import chalk from 'chalk'
|
|
4
|
-
import meow from 'meow'
|
|
5
|
-
import ora from 'ora'
|
|
6
|
-
|
|
7
|
-
import { outputFlags } from '../../flags/index.js'
|
|
8
|
-
import { handleApiCall, handleUnsuccessfulApiResponse } from '../../utils/api-helpers.js'
|
|
9
|
-
import { prepareFlags } from '../../utils/flags.js'
|
|
10
|
-
import { printFlagList } from '../../utils/formatting.js'
|
|
11
|
-
import { getDefaultKey, setupSdk } from '../../utils/sdk.js'
|
|
12
|
-
|
|
13
|
-
/** @type {import('../../utils/meow-with-subcommands.js').CliSubcommand} */
|
|
14
|
-
export const create = {
|
|
15
|
-
description: 'Create a repository in an organization',
|
|
16
|
-
async run (argv, importMeta, { parentName }) {
|
|
17
|
-
const name = parentName + ' create'
|
|
18
|
-
|
|
19
|
-
const input = setupCommand(name, create.description, argv, importMeta)
|
|
20
|
-
if (input) {
|
|
21
|
-
const spinnerText = 'Creating repository... \n'
|
|
22
|
-
const spinner = ora(spinnerText).start()
|
|
23
|
-
await createRepo(input.orgSlug, input, spinner)
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
const repositoryCreationFlags = 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
|
-
|
|
61
|
-
// Internal functions
|
|
62
|
-
|
|
63
|
-
/**
|
|
64
|
-
* @typedef CommandContext
|
|
65
|
-
* @property {boolean} outputJson
|
|
66
|
-
* @property {boolean} outputMarkdown
|
|
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
|
|
73
|
-
*/
|
|
74
|
-
|
|
75
|
-
/**
|
|
76
|
-
* @param {string} name
|
|
77
|
-
* @param {string} description
|
|
78
|
-
* @param {readonly string[]} argv
|
|
79
|
-
* @param {ImportMeta} importMeta
|
|
80
|
-
* @returns {void|CommandContext}
|
|
81
|
-
*/
|
|
82
|
-
function setupCommand (name, description, argv, importMeta) {
|
|
83
|
-
const flags = {
|
|
84
|
-
...outputFlags,
|
|
85
|
-
...repositoryCreationFlags
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
const cli = meow(`
|
|
89
|
-
Usage
|
|
90
|
-
$ ${name} <org slug>
|
|
91
|
-
|
|
92
|
-
Options
|
|
93
|
-
${printFlagList(flags, 6)}
|
|
94
|
-
|
|
95
|
-
Examples
|
|
96
|
-
$ ${name} FakeOrg --repoName=test-repo
|
|
97
|
-
`, {
|
|
98
|
-
argv,
|
|
99
|
-
description,
|
|
100
|
-
importMeta,
|
|
101
|
-
flags
|
|
102
|
-
})
|
|
103
|
-
|
|
104
|
-
const {
|
|
105
|
-
json: outputJson,
|
|
106
|
-
markdown: outputMarkdown,
|
|
107
|
-
repoName,
|
|
108
|
-
repoDescription,
|
|
109
|
-
homepage,
|
|
110
|
-
defaultBranch,
|
|
111
|
-
visibility
|
|
112
|
-
} = cli.flags
|
|
113
|
-
|
|
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
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
if (!repoName) {
|
|
123
|
-
console.error(`${chalk.bgRed('Input error')}: Repository name is required. \n`)
|
|
124
|
-
cli.showHelp()
|
|
125
|
-
return
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
return {
|
|
129
|
-
outputJson,
|
|
130
|
-
outputMarkdown,
|
|
131
|
-
orgSlug,
|
|
132
|
-
name: repoName,
|
|
133
|
-
description: repoDescription,
|
|
134
|
-
homepage,
|
|
135
|
-
default_branch: defaultBranch,
|
|
136
|
-
visibility
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
/**
|
|
141
|
-
* @typedef RepositoryData
|
|
142
|
-
* @property {import('@socketsecurity/sdk').SocketSdkReturnType<'createOrgRepo'>["data"]} data
|
|
143
|
-
*/
|
|
144
|
-
|
|
145
|
-
/**
|
|
146
|
-
* @param {string} orgSlug
|
|
147
|
-
* @param {CommandContext} input
|
|
148
|
-
* @param {import('ora').Ora} spinner
|
|
149
|
-
* @returns {Promise<void|RepositoryData>}
|
|
150
|
-
*/
|
|
151
|
-
async function createRepo (orgSlug, input, spinner) {
|
|
152
|
-
const socketSdk = await setupSdk(getDefaultKey())
|
|
153
|
-
const result = await handleApiCall(socketSdk.createOrgRepo(orgSlug, input), 'creating repository')
|
|
154
|
-
|
|
155
|
-
if (!result.success) {
|
|
156
|
-
return handleUnsuccessfulApiResponse('createOrgRepo', result, spinner)
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
spinner.stop()
|
|
160
|
-
|
|
161
|
-
console.log('\n✅ Repository created successfully \n')
|
|
162
|
-
|
|
163
|
-
return {
|
|
164
|
-
data: result.data
|
|
165
|
-
}
|
|
166
|
-
}
|
|
@@ -1,93 +0,0 @@
|
|
|
1
|
-
/* eslint-disable no-console */
|
|
2
|
-
|
|
3
|
-
import chalk from 'chalk'
|
|
4
|
-
import meow from 'meow'
|
|
5
|
-
import ora from 'ora'
|
|
6
|
-
|
|
7
|
-
import { handleApiCall, handleUnsuccessfulApiResponse } from '../../utils/api-helpers.js'
|
|
8
|
-
import { getDefaultKey, setupSdk } from '../../utils/sdk.js'
|
|
9
|
-
|
|
10
|
-
/** @type {import('../../utils/meow-with-subcommands.js').CliSubcommand} */
|
|
11
|
-
export const del = {
|
|
12
|
-
description: 'Delete a repository in an organization',
|
|
13
|
-
async run (argv, importMeta, { parentName }) {
|
|
14
|
-
const name = parentName + ' del'
|
|
15
|
-
|
|
16
|
-
const input = setupCommand(name, del.description, argv, importMeta)
|
|
17
|
-
if (input) {
|
|
18
|
-
const spinnerText = 'Deleting repository... \n'
|
|
19
|
-
const spinner = ora(spinnerText).start()
|
|
20
|
-
await deleteRepository(input.orgSlug, input.repoName, spinner)
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
// Internal functions
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
* @typedef CommandContext
|
|
29
|
-
* @property {string} orgSlug
|
|
30
|
-
* @property {string} repoName
|
|
31
|
-
*/
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* @param {string} name
|
|
35
|
-
* @param {string} description
|
|
36
|
-
* @param {readonly string[]} argv
|
|
37
|
-
* @param {ImportMeta} importMeta
|
|
38
|
-
* @returns {void|CommandContext}
|
|
39
|
-
*/
|
|
40
|
-
function setupCommand (name, description, argv, importMeta) {
|
|
41
|
-
const cli = meow(`
|
|
42
|
-
Usage
|
|
43
|
-
$ ${name} <org slug> <repo slug>
|
|
44
|
-
|
|
45
|
-
Examples
|
|
46
|
-
$ ${name} FakeOrg test-repo
|
|
47
|
-
`, {
|
|
48
|
-
argv,
|
|
49
|
-
description,
|
|
50
|
-
importMeta
|
|
51
|
-
})
|
|
52
|
-
|
|
53
|
-
const [orgSlug = '', repoName = ''] = cli.input
|
|
54
|
-
|
|
55
|
-
if (!orgSlug || !repoName) {
|
|
56
|
-
console.error(`${chalk.bgRed('Input error')}: Please provide an organization slug and repository slug \n`)
|
|
57
|
-
cli.showHelp()
|
|
58
|
-
return
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
return {
|
|
62
|
-
orgSlug,
|
|
63
|
-
repoName
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
/**
|
|
68
|
-
* @typedef RepositoryData
|
|
69
|
-
* @property {import('@socketsecurity/sdk').SocketSdkReturnType<'deleteOrgRepo'>["data"]} data
|
|
70
|
-
*/
|
|
71
|
-
|
|
72
|
-
/**
|
|
73
|
-
* @param {string} orgSlug
|
|
74
|
-
* @param {string} repoName
|
|
75
|
-
* @param {import('ora').Ora} spinner
|
|
76
|
-
* @returns {Promise<void|RepositoryData>}
|
|
77
|
-
*/
|
|
78
|
-
async function deleteRepository (orgSlug, repoName, spinner) {
|
|
79
|
-
const socketSdk = await setupSdk(getDefaultKey())
|
|
80
|
-
const result = await handleApiCall(socketSdk.deleteOrgRepo(orgSlug, repoName), 'deleting repository')
|
|
81
|
-
|
|
82
|
-
if (!result.success) {
|
|
83
|
-
return handleUnsuccessfulApiResponse('deleteOrgRepo', result, spinner)
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
spinner.stop()
|
|
87
|
-
|
|
88
|
-
console.log('\n✅ Repository deleted successfully \n')
|
|
89
|
-
|
|
90
|
-
return {
|
|
91
|
-
data: result.data
|
|
92
|
-
}
|
|
93
|
-
}
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import { create } from './create.js'
|
|
2
|
-
import { del } from './delete.js'
|
|
3
|
-
import { list } from './list.js'
|
|
4
|
-
import { update } from './update.js'
|
|
5
|
-
import { view } from './view.js'
|
|
6
|
-
import { meowWithSubcommands } from '../../utils/meow-with-subcommands.js'
|
|
7
|
-
|
|
8
|
-
const description = 'Repositories related commands'
|
|
9
|
-
|
|
10
|
-
/** @type {import('../../utils/meow-with-subcommands.js').CliSubcommand} */
|
|
11
|
-
export const repo = {
|
|
12
|
-
description,
|
|
13
|
-
run: async (argv, importMeta, { parentName }) => {
|
|
14
|
-
await meowWithSubcommands(
|
|
15
|
-
{
|
|
16
|
-
create,
|
|
17
|
-
view,
|
|
18
|
-
list,
|
|
19
|
-
del,
|
|
20
|
-
update
|
|
21
|
-
},
|
|
22
|
-
{
|
|
23
|
-
argv,
|
|
24
|
-
description,
|
|
25
|
-
importMeta,
|
|
26
|
-
name: parentName + ' repo',
|
|
27
|
-
}
|
|
28
|
-
)
|
|
29
|
-
}
|
|
30
|
-
}
|
|
@@ -1,170 +0,0 @@
|
|
|
1
|
-
/* eslint-disable no-console */
|
|
2
|
-
|
|
3
|
-
import chalk from 'chalk'
|
|
4
|
-
// @ts-ignore
|
|
5
|
-
import chalkTable from 'chalk-table'
|
|
6
|
-
import meow from 'meow'
|
|
7
|
-
import ora from 'ora'
|
|
8
|
-
|
|
9
|
-
import { outputFlags } from '../../flags/index.js'
|
|
10
|
-
import { handleApiCall, handleUnsuccessfulApiResponse } from '../../utils/api-helpers.js'
|
|
11
|
-
import { prepareFlags } from '../../utils/flags.js'
|
|
12
|
-
import { printFlagList } from '../../utils/formatting.js'
|
|
13
|
-
import { getDefaultKey, setupSdk } from '../../utils/sdk.js'
|
|
14
|
-
|
|
15
|
-
/** @type {import('../../utils/meow-with-subcommands.js').CliSubcommand} */
|
|
16
|
-
export const list = {
|
|
17
|
-
description: 'List repositories in an organization',
|
|
18
|
-
async run (argv, importMeta, { parentName }) {
|
|
19
|
-
const name = parentName + ' list'
|
|
20
|
-
|
|
21
|
-
const input = setupCommand(name, list.description, argv, importMeta)
|
|
22
|
-
if (input) {
|
|
23
|
-
const spinnerText = 'Listing repositories... \n'
|
|
24
|
-
const spinner = ora(spinnerText).start()
|
|
25
|
-
await listOrgRepos(input.orgSlug, input, spinner)
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
const listRepoFlags = prepareFlags({
|
|
31
|
-
sort: {
|
|
32
|
-
type: 'string',
|
|
33
|
-
shortFlag: 's',
|
|
34
|
-
default: 'created_at',
|
|
35
|
-
description: 'Sorting option',
|
|
36
|
-
},
|
|
37
|
-
direction: {
|
|
38
|
-
type: 'string',
|
|
39
|
-
default: 'desc',
|
|
40
|
-
description: 'Direction option',
|
|
41
|
-
},
|
|
42
|
-
perPage: {
|
|
43
|
-
type: 'number',
|
|
44
|
-
shortFlag: 'pp',
|
|
45
|
-
default: 30,
|
|
46
|
-
description: 'Number of results per page'
|
|
47
|
-
},
|
|
48
|
-
page: {
|
|
49
|
-
type: 'number',
|
|
50
|
-
shortFlag: 'p',
|
|
51
|
-
default: 1,
|
|
52
|
-
description: 'Page number'
|
|
53
|
-
},
|
|
54
|
-
})
|
|
55
|
-
|
|
56
|
-
// Internal functions
|
|
57
|
-
|
|
58
|
-
/**
|
|
59
|
-
* @typedef CommandContext
|
|
60
|
-
* @property {boolean} outputJson
|
|
61
|
-
* @property {boolean} outputMarkdown
|
|
62
|
-
* @property {string} orgSlug
|
|
63
|
-
* @property {string} sort
|
|
64
|
-
* @property {string} direction
|
|
65
|
-
* @property {number} per_page
|
|
66
|
-
* @property {number} page
|
|
67
|
-
*/
|
|
68
|
-
|
|
69
|
-
/**
|
|
70
|
-
* @param {string} name
|
|
71
|
-
* @param {string} description
|
|
72
|
-
* @param {readonly string[]} argv
|
|
73
|
-
* @param {ImportMeta} importMeta
|
|
74
|
-
* @returns {void|CommandContext}
|
|
75
|
-
*/
|
|
76
|
-
function setupCommand (name, description, argv, importMeta) {
|
|
77
|
-
const flags = {
|
|
78
|
-
...outputFlags,
|
|
79
|
-
...listRepoFlags
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
const cli = meow(`
|
|
83
|
-
Usage
|
|
84
|
-
$ ${name} <org slug>
|
|
85
|
-
|
|
86
|
-
Options
|
|
87
|
-
${printFlagList(flags, 6)}
|
|
88
|
-
|
|
89
|
-
Examples
|
|
90
|
-
$ ${name} FakeOrg
|
|
91
|
-
`, {
|
|
92
|
-
argv,
|
|
93
|
-
description,
|
|
94
|
-
importMeta,
|
|
95
|
-
flags
|
|
96
|
-
})
|
|
97
|
-
|
|
98
|
-
const {
|
|
99
|
-
json: outputJson,
|
|
100
|
-
markdown: outputMarkdown,
|
|
101
|
-
perPage,
|
|
102
|
-
sort,
|
|
103
|
-
direction,
|
|
104
|
-
page
|
|
105
|
-
} = cli.flags
|
|
106
|
-
|
|
107
|
-
if (!cli.input[0]) {
|
|
108
|
-
console.error(`${chalk.bgRed('Input error')}: Please provide an organization slug \n`)
|
|
109
|
-
cli.showHelp()
|
|
110
|
-
return
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
const [orgSlug = ''] = cli.input
|
|
114
|
-
|
|
115
|
-
return {
|
|
116
|
-
outputJson,
|
|
117
|
-
outputMarkdown,
|
|
118
|
-
orgSlug,
|
|
119
|
-
sort,
|
|
120
|
-
direction,
|
|
121
|
-
page,
|
|
122
|
-
per_page: perPage
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
/**
|
|
127
|
-
* @typedef RepositoryData
|
|
128
|
-
* @property {import('@socketsecurity/sdk').SocketSdkReturnType<'getOrgRepoList'>["data"]} data
|
|
129
|
-
*/
|
|
130
|
-
|
|
131
|
-
/**
|
|
132
|
-
* @param {string} orgSlug
|
|
133
|
-
* @param {CommandContext} input
|
|
134
|
-
* @param {import('ora').Ora} spinner
|
|
135
|
-
* @returns {Promise<void|RepositoryData>}
|
|
136
|
-
*/
|
|
137
|
-
async function listOrgRepos (orgSlug, input, spinner) {
|
|
138
|
-
const socketSdk = await setupSdk(getDefaultKey())
|
|
139
|
-
const result = await handleApiCall(socketSdk.getOrgRepoList(orgSlug, input), 'listing repositories')
|
|
140
|
-
|
|
141
|
-
if (!result.success) {
|
|
142
|
-
return handleUnsuccessfulApiResponse('getOrgRepoList', result, spinner)
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
spinner.stop()
|
|
146
|
-
|
|
147
|
-
const options = {
|
|
148
|
-
columns: [
|
|
149
|
-
{ field: 'id', name: chalk.magenta('ID') },
|
|
150
|
-
{ field: 'name', name: chalk.magenta('Name') },
|
|
151
|
-
{ field: 'visibility', name: chalk.magenta('Visibility') },
|
|
152
|
-
{ field: 'default_branch', name: chalk.magenta('Default branch') },
|
|
153
|
-
{ field: 'archived', name: chalk.magenta('Archived') }
|
|
154
|
-
]
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
const formattedResults = result.data.results.map(d => {
|
|
158
|
-
return {
|
|
159
|
-
...d
|
|
160
|
-
}
|
|
161
|
-
})
|
|
162
|
-
|
|
163
|
-
const table = chalkTable(options, formattedResults)
|
|
164
|
-
|
|
165
|
-
console.log(table, '\n')
|
|
166
|
-
|
|
167
|
-
return {
|
|
168
|
-
data: result.data
|
|
169
|
-
}
|
|
170
|
-
}
|