Skip to content

Commit 09d889d

Browse files
committed
Move filtering of info to where newVersion is resolved
1 parent fe34a4d commit 09d889d

File tree

1 file changed

+15
-30
lines changed

1 file changed

+15
-30
lines changed

src/commands/fix/pnpm-fix.mts

Lines changed: 15 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -299,20 +299,18 @@ export async function pnpmFix(
299299
const infoEntry = sortedInfoEntries[i]!
300300
const partialPurlObj = getPurlObject(infoEntry[0])
301301
const name = resolvePackageName(partialPurlObj)
302-
let infos = [...infoEntry[1].values()]
302+
303+
const infos = [...infoEntry[1].values()]
304+
if (!infos.length) {
305+
continue infoEntriesLoop
306+
}
307+
308+
const activeBranches: SocketBranchParseResult[] = []
303309
if (isCi) {
304310
const branchFullName = getSocketBranchFullNameComponent(partialPurlObj)
305311
const branchPurlType = getSocketBranchPurlTypeComponent(partialPurlObj)
306-
const activeBranches: SocketBranchParseResult[] = []
307312
for (const pr of openPrs) {
308313
const parsedBranch = branchParser!(pr.headRefName)
309-
debugFn(`parse: ${pr.headRefName}\n`, parsedBranch)
310-
debugFn(
311-
`check: branchPurlType ${branchPurlType} === ${parsedBranch?.type}`,
312-
)
313-
debugFn(
314-
`check: branchFullName ${branchFullName} === ${parsedBranch?.fullName}`,
315-
)
316314
if (
317315
branchPurlType === parsedBranch?.type &&
318316
branchFullName === parsedBranch?.fullName
@@ -328,26 +326,6 @@ export async function pnpmFix(
328326
} else if (openPrs.length) {
329327
debugFn('miss: 0 active branches found')
330328
}
331-
infos = infos.filter(info => {
332-
const found = activeBranches.find(
333-
b => b.newVersion === info.firstPatchedVersionIdentifier,
334-
)
335-
if (found) {
336-
debugFn(
337-
`found: active branch for ${name}@${info.firstPatchedVersionIdentifier}`,
338-
)
339-
return false
340-
} else {
341-
debugFn(
342-
`miss: no active branch found for ${name}@${info.firstPatchedVersionIdentifier}`,
343-
)
344-
return true
345-
}
346-
})
347-
}
348-
349-
if (!infos.length) {
350-
continue infoEntriesLoop
351329
}
352330

353331
logger.log(`Processing vulns for ${name}:`)
@@ -459,17 +437,24 @@ export async function pnpmFix(
459437
infosLoop: for (const {
460438
firstPatchedVersionIdentifier,
461439
vulnerableVersionRange,
462-
} of infos.values()) {
440+
} of infos) {
463441
if (semver.gte(oldVersion, firstPatchedVersionIdentifier)) {
464442
debugFn(`skip: ${oldId} is >= ${firstPatchedVersionIdentifier}`)
465443
continue infosLoop
466444
}
445+
467446
const newVersion = findBestPatchVersion(
468447
node,
469448
availableVersions,
470449
vulnerableVersionRange,
471450
firstPatchedVersionIdentifier,
472451
)
452+
453+
if (activeBranches.find(b => b.newVersion === newVersion)) {
454+
debugFn(`skip: open PR found for ${name}@${newVersion}`)
455+
continue infosLoop
456+
}
457+
473458
const newVersionPackument = newVersion
474459
? packument.versions[newVersion]
475460
: undefined

0 commit comments

Comments
 (0)