Skip to content

Commit 764bdfb

Browse files
committed
update view command
1 parent 49eadb7 commit 764bdfb

File tree

2 files changed

+46
-20
lines changed

2 files changed

+46
-20
lines changed

lib/commands/repos/list.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ function setupCommand (name, description, argv, importMeta) {
137137
async function listOrgRepos (orgSlug, input, spinner) {
138138
const socketSdk = await setupSdk(getDefaultKey())
139139
// @ts-ignore
140-
const result = await handleApiCall(socketSdk.getOrgRepoList(orgSlug, input), 'looking up package')
140+
const result = await handleApiCall(socketSdk.getOrgRepoList(orgSlug, input), 'listing repositories')
141141

142142
if (!result.success) {
143143
return handleUnsuccessfulApiResponse('getOrgRepoList', result, spinner)

lib/commands/repos/view.js

Lines changed: 45 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
1-
// @ts-nocheck
21
/* eslint-disable no-console */
32

3+
import chalk from 'chalk'
4+
// @ts-ignore
5+
import chalkTable from 'chalk-table'
46
import meow from 'meow'
57
import ora from 'ora'
68

79
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'
1011
import { printFlagList } from '../../utils/formatting.js'
11-
// import { getDefaultKey, setupSdk } from '../../utils/sdk.js'
12+
import { getDefaultKey, setupSdk } from '../../utils/sdk.js'
1213

1314
/** @type {import('../../utils/meow-with-subcommands.js').CliSubcommand} */
1415
export const view = {
@@ -20,7 +21,7 @@ export const view = {
2021
if (input) {
2122
const spinnerText = 'Fetching repository... \n'
2223
const spinner = ora(spinnerText).start()
23-
await viewRepository(input.orgSlug, input, spinner)
24+
await viewRepository(input.orgSlug, input.repositoryName, spinner)
2425
}
2526
}
2627
}
@@ -32,6 +33,7 @@ export const view = {
3233
* @property {boolean} outputJson
3334
* @property {boolean} outputMarkdown
3435
* @property {string} orgSlug
36+
* @property {string} repositoryName
3537
*/
3638

3739
/**
@@ -68,37 +70,61 @@ function setupCommand (name, description, argv, importMeta) {
6870
} = cli.flags
6971

7072
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
7576
}
7677

77-
const orgSlug = cli.input[0] || ''
78+
const [orgSlug = '', repositoryName = ''] = cli.input
7879

7980
return {
8081
outputJson,
8182
outputMarkdown,
82-
orgSlug
83+
orgSlug,
84+
repositoryName
8385
}
8486
}
8587

8688
/**
8789
* @typedef RepositoryData
88-
* @property {import('@socketsecurity/sdk').SocketSdkReturnType<'getOrgFullScanList'>["data"]} data
90+
* @property {import('@socketsecurity/sdk').SocketSdkReturnType<'getOrgRepo'>["data"]} data
8991
*/
9092

9193
/**
9294
* @param {string} orgSlug
93-
* @param {CommandContext} input
95+
* @param {string} repoName
9496
* @param {import('ora').Ora} spinner
9597
* @returns {Promise<void|RepositoryData>}
9698
*/
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')
100103

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+
}
104130
}

0 commit comments

Comments
 (0)