Skip to content

Commit

Permalink
update view command
Browse files Browse the repository at this point in the history
  • Loading branch information
charliegerard committed Jun 18, 2024
1 parent 826af0d commit eba5d20
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 20 deletions.
2 changes: 1 addition & 1 deletion lib/commands/repos/list.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ function setupCommand (name, description, argv, importMeta) {
async function listOrgRepos (orgSlug, input, spinner) {
const socketSdk = await setupSdk(getDefaultKey())
// @ts-ignore
const result = await handleApiCall(socketSdk.getOrgRepoList(orgSlug, input), 'looking up package')
const result = await handleApiCall(socketSdk.getOrgRepoList(orgSlug, input), 'listing repositories')

if (!result.success) {
return handleUnsuccessfulApiResponse('getOrgRepoList', result, spinner)
Expand Down
64 changes: 45 additions & 19 deletions lib/commands/repos/view.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
// @ts-nocheck
/* eslint-disable no-console */

import chalk from 'chalk'
// @ts-ignore
import chalkTable from 'chalk-table'
import meow from 'meow'
import ora from 'ora'

import { outputFlags } from '../../flags/index.js'
// import { handleApiCall, handleUnsuccessfulApiResponse } from '../../utils/api-helpers.js'
import { InputError } from '../../utils/errors.js'
import { handleApiCall, handleUnsuccessfulApiResponse } from '../../utils/api-helpers.js'
import { printFlagList } from '../../utils/formatting.js'
// import { getDefaultKey, setupSdk } from '../../utils/sdk.js'
import { getDefaultKey, setupSdk } from '../../utils/sdk.js'

/** @type {import('../../utils/meow-with-subcommands.js').CliSubcommand} */
export const view = {
Expand All @@ -20,7 +21,7 @@ export const view = {
if (input) {
const spinnerText = 'Fetching repository... \n'
const spinner = ora(spinnerText).start()
await viewRepository(input.orgSlug, input, spinner)
await viewRepository(input.orgSlug, input.repositoryName, spinner)
}
}
}
Expand All @@ -32,6 +33,7 @@ export const view = {
* @property {boolean} outputJson
* @property {boolean} outputMarkdown
* @property {string} orgSlug
* @property {string} repositoryName
*/

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

if (!cli.input[0]) {
throw new InputError(`Please specify an organization slug. \n
Example:
socket scan list FakeOrg
`)
console.error(`${chalk.bgRed('Input error')}: Please provide an organization slug \n`)
cli.showHelp()
return
}

const orgSlug = cli.input[0] || ''
const [orgSlug = '', repositoryName = ''] = cli.input

return {
outputJson,
outputMarkdown,
orgSlug
orgSlug,
repositoryName
}
}

/**
* @typedef RepositoryData
* @property {import('@socketsecurity/sdk').SocketSdkReturnType<'getOrgFullScanList'>["data"]} data
* @property {import('@socketsecurity/sdk').SocketSdkReturnType<'getOrgRepo'>["data"]} data
*/

/**
* @param {string} orgSlug
* @param {CommandContext} input
* @param {string} repoName
* @param {import('ora').Ora} spinner
* @returns {Promise<void|RepositoryData>}
*/
async function viewRepository (orgSlug, input, spinner) {
// const socketSdk = await setupSdk(getDefaultKey())
console.log(input)
async function viewRepository (orgSlug, repoName, spinner) {
const socketSdk = await setupSdk(getDefaultKey())
// @ts-ignore
const result = await handleApiCall(socketSdk.getOrgRepo(orgSlug, repoName), 'fetching repository')

// return {
// // data: result.data
// }
if (!result.success) {
return handleUnsuccessfulApiResponse('getOrgRepo', result, spinner)
}

spinner.stop()

const options = {
columns: [
{ field: 'id', name: chalk.magenta('ID') },
{ field: 'name', name: chalk.magenta('Name') },
{ field: 'visibility', name: chalk.magenta('Visibility') },
{ field: 'default_branch', name: chalk.magenta('Default branch') },
{ field: 'homepage', name: chalk.magenta('Homepage') },
{ field: 'archived', name: chalk.magenta('Archived') },
{ field: 'created_at', name: chalk.magenta('Created at') }
]
}

const table = chalkTable(options, [result.data])

console.log(table, '\n')

return {
// @ts-ignore
data: result.data
}
}

0 comments on commit eba5d20

Please sign in to comment.