Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/commands/report/cmd-report-create.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,15 @@ describe('socket report create', async () => {
'should require args with just dry-run',
async cmd => {
const { code, stderr, stdout } = await invokeNpm(entryPath, cmd)
expect(stdout).toMatchInlineSnapshot(`"[DryRun]: Bailing now"`)
expect(stdout).toMatchInlineSnapshot(`""`)
expect(`\n ${stderr}`).toMatchInlineSnapshot(`
"
_____ _ _ /---------------
| __|___ ___| |_ ___| |_ | Socket.dev CLI ver <redacted>
|__ | . | _| '_| -_| _| | Node: <redacted>, API token set: <redacted>
|_____|___|___|_,_|___|_|.dev | Command: \`socket report create\`, cwd: <redacted>"
|_____|___|___|_,_|___|_|.dev | Command: \`socket report create\`, cwd: <redacted>

\\x1b[31m\\xd7\\x1b[39m This command has been sunset. Instead, please look at \`socket scan create\` to create scans and \`socket scan report\` to view a report of your scans."
`)

expect(code, 'dry-run should exit with code 0 if input ok').toBe(0)
Expand Down
55 changes: 4 additions & 51 deletions src/commands/report/cmd-report-create.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,10 @@
import path from 'node:path'

import { logger } from '@socketsecurity/registry/lib/logger'

import { createReport } from './create-report'
import { getSocketConfig } from './get-socket-config'
import { viewReport } from './view-report'
import constants from '../../constants'
import { commonFlags, outputFlags, validationFlags } from '../../flags'
import { ColorOrMarkdown } from '../../utils/color-or-markdown'
import { meowOrExit } from '../../utils/meow-with-subcommands'

import type { CliCommandConfig } from '../../utils/meow-with-subcommands'

const { DRY_RUN_BAIL_TEXT } = constants

const config: CliCommandConfig = {
commandName: 'create',
description: '[Deprecated] Create a project report',
Expand Down Expand Up @@ -51,52 +42,14 @@ async function run(
importMeta: ImportMeta,
{ parentName }: { parentName: string }
): Promise<void> {
const cli = meowOrExit({
meowOrExit({
argv,
config,
importMeta,
parentName
})

// TODO: Allow setting a custom cwd and/or configFile path?
const cwd = process.cwd()
const absoluteConfigPath = path.join(cwd, 'socket.yml')

const dryRun = Boolean(cli.flags['dryRun'])
const json = Boolean(cli.flags['json'])
const markdown = Boolean(cli.flags['markdown'])
const strict = Boolean(cli.flags['strict'])
const includeAllIssues = Boolean(cli.flags['all'])
const view = Boolean(cli.flags['view'])

// Note exiting earlier to skirt a hidden auth requirement
if (cli.flags['dryRun']) {
logger.log(DRY_RUN_BAIL_TEXT)
return
}

const socketConfig = await getSocketConfig(absoluteConfigPath)

const result = await createReport(socketConfig, cli.input, { cwd, dryRun })

const commandName = `${parentName} ${config.commandName}`

if (result?.success) {
if (view) {
const reportId = result.data.id
await viewReport(reportId, {
all: includeAllIssues,
commandName,
outputKind: json ? 'json' : markdown ? 'markdown' : 'print',
strict
})
} else if (json) {
logger.log(JSON.stringify(result.data, undefined, 2))
} else {
const format = new ColorOrMarkdown(markdown)
logger.log(
`New report: ${format.hyperlink(result.data.id, result.data.url, { fallbackToUrl: true })}`
)
}
}
logger.fail(
'This command has been sunset. Instead, please look at `socket scan create` to create scans and `socket scan report` to view a report of your scans.'
)
}
6 changes: 4 additions & 2 deletions src/commands/report/cmd-report-view.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,15 @@ describe('socket report create', async () => {
'should require args with just dry-run',
async cmd => {
const { code, stderr, stdout } = await invokeNpm(entryPath, cmd)
expect(stdout).toMatchInlineSnapshot(`"[DryRun]: Bailing now"`)
expect(stdout).toMatchInlineSnapshot(`""`)
expect(`\n ${stderr}`).toMatchInlineSnapshot(`
"
_____ _ _ /---------------
| __|___ ___| |_ ___| |_ | Socket.dev CLI ver <redacted>
|__ | . | _| '_| -_| _| | Node: <redacted>, API token set: <redacted>
|_____|___|___|_,_|___|_|.dev | Command: \`socket report create\`, cwd: <redacted>"
|_____|___|___|_,_|___|_|.dev | Command: \`socket report create\`, cwd: <redacted>

\\x1b[31m\\xd7\\x1b[39m This command has been sunset. Instead, please look at \`socket scan create\` to create scans and \`socket scan report\` to view a report of your scans."
`)

expect(code, 'dry-run should exit with code 0 if input ok').toBe(0)
Expand Down
48 changes: 3 additions & 45 deletions src/commands/report/cmd-report-view.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,10 @@
import { logger } from '@socketsecurity/registry/lib/logger'

import { viewReport } from './view-report'
import constants from '../../constants'
import { commonFlags, outputFlags, validationFlags } from '../../flags'
import { handleBadInput } from '../../utils/handle-bad-input'
import { meowOrExit } from '../../utils/meow-with-subcommands'

import type { CliCommandConfig } from '../../utils/meow-with-subcommands'

const { DRY_RUN_BAIL_TEXT } = constants

const config: CliCommandConfig = {
commandName: 'view',
description: '[Deprecated] View a project report',
Expand All @@ -36,51 +31,14 @@ async function run(
importMeta: ImportMeta,
{ parentName }: { parentName: string }
): Promise<void> {
const cli = meowOrExit({
meowOrExit({
argv,
config,
importMeta,
parentName
})

const { json, markdown } = cli.flags
const [reportId = '', ...extraInput] = cli.input

const wasBadInput = handleBadInput(
{
test: reportId,
message: 'Need at least one report ID',
pass: 'ok',
fail: 'missing'
},
{
nook: true,
test: extraInput.length === 0,
message: 'Can only handle a single report ID',
pass: 'ok',
fail: 'received ' + (extraInput.length + 1)
},
{
nook: true,
test: !json || !markdown,
message: 'The json and markdown flags cannot be both set, pick one',
pass: 'ok',
fail: 'omit one'
}
logger.fail(
'This command has been sunset. Instead, please look at `socket scan create` to create scans and `socket scan report` to view a report of your scans.'
)
if (wasBadInput) {
return
}

if (cli.flags['dryRun']) {
logger.log(DRY_RUN_BAIL_TEXT)
return
}

await viewReport(reportId, {
all: Boolean(cli.flags['all']),
commandName: `${parentName} ${config.commandName}`,
outputKind: json ? 'json' : markdown ? 'markdown' : 'print',
strict: Boolean(cli.flags['strict'])
})
}
74 changes: 0 additions & 74 deletions src/commands/report/create-report.ts

This file was deleted.

76 changes: 0 additions & 76 deletions src/commands/report/fetch-report-data.ts

This file was deleted.

44 changes: 0 additions & 44 deletions src/commands/report/format-report-data.ts

This file was deleted.

Loading