Skip to content

Commit 7596b61

Browse files
committed
Simplify coana auto fix
1 parent 6f0469c commit 7596b61

File tree

2 files changed

+7
-32
lines changed

2 files changed

+7
-32
lines changed

src/commands/fix/cmd-fix.mts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ const config: CliCommandConfig = {
4747
description: `Provide a list of ${terminalLink(
4848
'GHSA IDs',
4949
'https://docs.github.com/en/code-security/security-advisories/working-with-global-security-advisories-from-the-github-advisory-database/about-the-github-advisory-database#about-ghsa-ids',
50-
)} to compute fixes for, as either a comma separated value or as multiple flags.\n Use '--ghsa auto' to automatically lookup GHSA IDs and compute fixes for them.`,
50+
)} to compute fixes for, as either a comma separated value or as multiple flags.\n Use '--ghsa all' to lookup all GHSA IDs and compute fixes for them.`,
5151
isMultiple: true,
5252
hidden: true,
5353
},

src/commands/fix/coana-fix.mts

Lines changed: 6 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
import { debugDir, debugFn } from '@socketsecurity/registry/lib/debug'
1+
import { debugDir } from '@socketsecurity/registry/lib/debug'
22

33
import { handleApiCall } from '../../utils/api.mts'
4-
import { cmdFlagValueToArray } from '../../utils/cmd.mts'
54
import { spawnCoana } from '../../utils/coana.mts'
65
import { getPackageFilesForScan } from '../../utils/path-resolve.mts'
76
import { setupSdk } from '../../utils/sdk.mts'
@@ -64,34 +63,10 @@ export async function coanaFix(
6463
return lastCResult as CResult<any>
6564
}
6665

67-
const spawnOptions = { cwd, spinner, env: { SOCKET_ORG_SLUG: orgSlug } }
68-
69-
let ids = ghsas
70-
if (ids.length === 1 && ids[0] === 'auto') {
71-
debugFn('notice', 'resolve: GitHub security alerts.')
72-
const foundIdsCResult = tarHash
73-
? await spawnCoana(
74-
[
75-
'compute-fixes-and-upgrade-purls',
76-
cwd,
77-
'--manifests-tar-hash',
78-
tarHash,
79-
],
80-
spawnOptions,
81-
)
82-
: undefined
83-
if (foundIdsCResult) {
84-
lastCResult = foundIdsCResult
85-
}
86-
if (foundIdsCResult?.ok) {
87-
ids = cmdFlagValueToArray(
88-
/(?<=Vulnerabilities found: )[^\n]+/.exec(
89-
foundIdsCResult.data as string,
90-
)?.[0],
91-
)
92-
debugDir('inspect', { GitHubSecurityAlerts: ids })
93-
}
94-
}
66+
const isAuto =
67+
ghsas.length === 1 && (ghsas[0] === 'all' || ghsas[0] === 'auto')
68+
69+
const ids = isAuto ? ['all'] : ghsas
9570

9671
const fixCResult = ids.length
9772
? await spawnCoana(
@@ -104,7 +79,7 @@ export async function coanaFix(
10479
...ids,
10580
...fixConfig.unknownFlags,
10681
],
107-
spawnOptions,
82+
{ cwd, spinner, env: { SOCKET_ORG_SLUG: orgSlug } },
10883
)
10984
: undefined
11085

0 commit comments

Comments
 (0)