Skip to content

Commit 8d241a3

Browse files
committed
Claude improvements and cleanup
1 parent 7c9782e commit 8d241a3

15 files changed

+384
-200
lines changed

src/commands.mts

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,8 @@ export const rootCommands = {
6060

6161
export const rootAliases = {
6262
audit: {
63-
description: cmdAuditLog.description,
64-
hidden: true,
63+
description: `${cmdAuditLog.description} (alias)`,
64+
hidden: false,
6565
argv: ['audit-log'],
6666
},
6767
auditLog: {
@@ -80,18 +80,18 @@ export const rootAliases = {
8080
argv: ['audit-log'],
8181
},
8282
deps: {
83-
description: cmdOrganizationDependencies.description,
84-
hidden: true,
83+
description: `${cmdOrganizationDependencies.description} (alias)`,
84+
hidden: false,
8585
argv: ['dependencies'],
8686
},
8787
feed: {
88-
description: cmdThreatFeed.description,
89-
hidden: true,
88+
description: `${cmdThreatFeed.description} (alias)`,
89+
hidden: false,
9090
argv: ['threat-feed'],
9191
},
9292
org: {
93-
description: cmdOrganization.description,
94-
hidden: true,
93+
description: `${cmdOrganization.description} (alias)`,
94+
hidden: false,
9595
argv: ['organization'],
9696
},
9797
orgs: {
@@ -115,13 +115,13 @@ export const rootAliases = {
115115
argv: ['organization'],
116116
},
117117
pkg: {
118-
description: cmdPackage.description,
119-
hidden: true,
118+
description: `${cmdPackage.description} (alias)`,
119+
hidden: false,
120120
argv: ['package'],
121121
},
122122
repo: {
123-
description: cmdRepository.description,
124-
hidden: true,
123+
description: `${cmdRepository.description} (alias)`,
124+
hidden: false,
125125
argv: ['repos'],
126126
},
127127
repos: {

src/commands/ci/handle-ci.mts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,11 @@ import { logger } from '@socketsecurity/registry/lib/logger'
22

33
import { getDefaultOrgSlug } from './fetch-default-org-slug.mts'
44
import constants from '../../constants.mts'
5-
import { getRepoName, gitBranch } from '../../utils/git.mts'
5+
import {
6+
detectDefaultBranch,
7+
getRepoName,
8+
gitBranch,
9+
} from '../../utils/git.mts'
610
import { serializeResultJson } from '../../utils/serialize-result-json.mts'
711
import { handleCreateNewScan } from '../scan/handle-create-new-scan.mts'
812

@@ -18,7 +22,7 @@ export async function handleCi(autoManifest: boolean): Promise<void> {
1822
const orgSlug = orgSlugCResult.data
1923
const cwd = process.cwd()
2024
// Lazily access constants.SOCKET_DEFAULT_BRANCH.
21-
const branchName = (await gitBranch(cwd)) || constants.SOCKET_DEFAULT_BRANCH
25+
const branchName = (await gitBranch(cwd)) || (await detectDefaultBranch(cwd))
2226
// Lazily access constants.SOCKET_DEFAULT_REPOSITORY.
2327
const repoName =
2428
(await getRepoName(cwd)) || constants.SOCKET_DEFAULT_REPOSITORY

src/commands/login/cmd-login.mts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ async function run(
8181

8282
if (!isInteractive()) {
8383
throw new InputError(
84-
'Cannot prompt for credentials in a non-interactive shell',
84+
'Cannot prompt for credentials in a non-interactive shell. Use SOCKET_CLI_API_TOKEN environment variable instead',
8585
)
8686
}
8787

src/commands/manifest/cmd-manifest-conda.test.mts

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -128,10 +128,7 @@ describe('socket manifest conda', async () => {
128128
`)
129129
expect(`\n ${stderr}`).toMatchInlineSnapshot(`
130130
"
131-
_____ _ _ /---------------
132-
| __|___ ___| |_ ___| |_ | Socket.dev CLI ver <redacted>
133-
|__ | * | _| '_| -_| _| | Node: <redacted>, API token: <redacted>, org: <redacted>
134-
|_____|___|___|_,_|___|_|.dev | Command: \`socket manifest conda\`, cwd: <redacted>"
131+
"
135132
`)
136133
},
137134
)
@@ -152,12 +149,7 @@ describe('socket manifest conda', async () => {
152149
expect(stdout).toMatchInlineSnapshot(`""`)
153150
expect(`\n ${stderr}`).toMatchInlineSnapshot(`
154151
"
155-
_____ _ _ /---------------
156-
| __|___ ___| |_ ___| |_ | Socket.dev CLI ver <redacted>
157-
|__ | * | _| '_| -_| _| | Node: <redacted>, API token: <redacted>, org: <redacted>
158-
|_____|___|___|_,_|___|_|.dev | Command: \`socket manifest conda\`, cwd: <redacted>
159-
160-
\\xd7 Input error: Please review the input requirements and try again
152+
\\xd7 Input error: Please review the input requirements and try again
161153
162154
\\xd7 Can only accept one DIR (make sure to escape spaces!) (received 2)"
163155
`)

src/commands/package/output-purls-shallow-score.mts

Lines changed: 56 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -61,35 +61,56 @@ export function outputPurlsShallowScore(
6161
logger.log(txt)
6262
}
6363

64-
function formatReportCard(artifact: DedupedArtifact, color: boolean): string {
64+
function formatReportCard(
65+
artifact: DedupedArtifact,
66+
colorize: boolean,
67+
): string {
6568
const scoreResult = {
6669
'Supply Chain Risk': Math.floor((artifact.score?.supplyChain ?? 0) * 100),
6770
Maintenance: Math.floor((artifact.score?.maintenance ?? 0) * 100),
6871
Quality: Math.floor((artifact.score?.quality ?? 0) * 100),
6972
Vulnerabilities: Math.floor((artifact.score?.vulnerability ?? 0) * 100),
7073
License: Math.floor((artifact.score?.license ?? 0) * 100),
7174
}
72-
const alertString = getAlertString(artifact.alerts, !color)
75+
const alertString = getAlertString(artifact.alerts, { colorize })
7376
if (!artifact.ecosystem) {
7477
debugFn('notice', 'miss: artifact ecosystem', artifact)
7578
}
7679
const purl = `pkg:${artifact.ecosystem}/${artifact.name}${artifact.version ? '@' + artifact.version : ''}`
7780

81+
// Calculate proper padding based on longest label.
82+
const maxLabelLength = Math.max(
83+
...Object.keys(scoreResult).map(label => label.length),
84+
)
85+
const labelPadding = maxLabelLength + 2 // +2 for ": "
86+
7887
return [
79-
'Package: ' + (color ? colors.bold(purl) : purl),
88+
'Package: ' + (colorize ? colors.bold(purl) : purl),
8089
'',
8190
...Object.entries(scoreResult).map(
8291
score =>
83-
`- ${score[0]}:`.padEnd(20, ' ') +
84-
` ${formatScore(score[1], !color, true)}`,
92+
`- ${score[0]}:`.padEnd(labelPadding, ' ') +
93+
` ${formatScore(score[1], { colorize })}`,
8594
),
8695
alertString,
8796
].join('\n')
8897
}
8998

90-
function formatScore(score: number, noColor = false, pad = false): string {
91-
const padded = String(score).padStart(pad ? 3 : 0, ' ')
92-
if (noColor) {
99+
type FormatScoreOptions = {
100+
colorize?: boolean | undefined
101+
padding?: number | undefined
102+
}
103+
104+
function formatScore(
105+
score: number,
106+
options?: FormatScoreOptions | undefined,
107+
): string {
108+
const { colorize, padding = 3 } = {
109+
__proto__: null,
110+
...options,
111+
} as FormatScoreOptions
112+
const padded = String(score).padStart(padding, ' ')
113+
if (!colorize) {
93114
return padded
94115
}
95116
if (score >= 80) {
@@ -101,61 +122,63 @@ function formatScore(score: number, noColor = false, pad = false): string {
101122
return colors.red(padded)
102123
}
103124

125+
type AlertStringOptions = {
126+
colorize?: boolean | undefined
127+
}
128+
104129
function getAlertString(
105130
alerts: DedupedArtifact['alerts'],
106-
noColor = false,
131+
options?: AlertStringOptions | undefined,
107132
): string {
133+
const { colorize } = { __proto__: null, ...options } as AlertStringOptions
134+
108135
if (!alerts.size) {
109-
return noColor ? `- Alerts: none!` : `- Alerts: ${colors.green('none')}!`
136+
return `- Alerts: ${colorize ? colors.green('none') : 'none'}!`
110137
}
111138

112139
const o = Array.from(alerts.values())
140+
113141
const bad = o
114142
.filter(alert => alert.severity !== 'low' && alert.severity !== 'middle')
115143
.sort((a, b) => (a.type < b.type ? -1 : a.type > b.type ? 1 : 0))
144+
116145
const mid = o
117146
.filter(alert => alert.severity === 'middle')
118147
.sort((a, b) => (a.type < b.type ? -1 : a.type > b.type ? 1 : 0))
148+
119149
const low = o
120150
.filter(alert => alert.severity === 'low')
121151
.sort((a, b) => (a.type < b.type ? -1 : a.type > b.type ? 1 : 0))
122152

123153
// We need to create the no-color string regardless because the actual string
124154
// contains a bunch of invisible ANSI chars which would screw up length checks.
125155
const colorless = `- Alerts (${bad.length}/${mid.length.toString()}/${low.length}):`
156+
const padding = ` ${' '.repeat(Math.max(0, 20 - colorless.length))}`
126157

127-
if (noColor) {
158+
if (colorize) {
128159
return (
129-
colorless +
130-
' '.repeat(Math.max(0, 20 - colorless.length)) +
131-
' ' +
160+
`- Alerts (${colors.red(bad.length.toString())}/${colors.yellow(mid.length.toString())}/${low.length}):` +
161+
padding +
132162
[
133-
bad.map(alert => `[${alert.severity}] ` + alert.type).join(', '),
134-
mid.map(alert => `[${alert.severity}] ` + alert.type).join(', '),
135-
low.map(alert => `[${alert.severity}] ` + alert.type).join(', '),
163+
bad
164+
.map(a => colors.red(`${colors.dim(`[${a.severity}] `)}${a.type}`))
165+
.join(', '),
166+
mid
167+
.map(a => colors.yellow(`${colors.dim(`[${a.severity}] `)}${a.type}`))
168+
.join(', '),
169+
low.map(a => `${colors.dim(`[${a.severity}] `)}${a.type}`).join(', '),
136170
]
137171
.filter(Boolean)
138172
.join(', ')
139173
)
140174
}
141175
return (
142-
`- Alerts (${colors.red(bad.length.toString())}/${colors.yellow(mid.length.toString())}/${low.length}):` +
143-
' '.repeat(Math.max(0, 20 - colorless.length)) +
144-
' ' +
176+
colorless +
177+
padding +
145178
[
146-
bad
147-
.map(alert =>
148-
colors.red(colors.dim(`[${alert.severity}] `) + alert.type),
149-
)
150-
.join(', '),
151-
mid
152-
.map(alert =>
153-
colors.yellow(colors.dim(`[${alert.severity}] `) + alert.type),
154-
)
155-
.join(', '),
156-
low
157-
.map(alert => colors.dim(`[${alert.severity}] `) + alert.type)
158-
.join(', '),
179+
bad.map(a => `[${a.severity}] ${a.type}`).join(', '),
180+
mid.map(a => `[${a.severity}] ${a.type}`).join(', '),
181+
low.map(a => `[${a.severity}] ${a.type}`).join(', '),
159182
]
160183
.filter(Boolean)
161184
.join(', ')

0 commit comments

Comments
 (0)