Skip to content

Commit a3e4270

Browse files
committed
refactor(fix): DRY out package deduplication with getUniquePackages helper
1 parent 6d1f49c commit a3e4270

File tree

1 file changed

+15
-14
lines changed

1 file changed

+15
-14
lines changed

src/commands/fix/git.mts

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,19 @@ import type { GhsaDetails } from '../../utils/github.mts'
66

77
const GITHUB_ADVISORIES_URL = 'https://github.com/advisories'
88

9+
/**
10+
* Extract unique package names with ecosystems from vulnerability details.
11+
*/
12+
function getUniquePackages(details: GhsaDetails): string[] {
13+
return [
14+
...new Set(
15+
details.vulnerabilities.nodes.map(
16+
v => `${v.package.name} (${v.package.ecosystem})`,
17+
),
18+
),
19+
]
20+
}
21+
922
export type SocketFixBranchParser = (
1023
branch: string,
1124
) => SocketFixBranchParseResult | undefined
@@ -60,13 +73,7 @@ export function getSocketFixPullRequestBody(
6073
if (!details) {
6174
return body
6275
}
63-
const packages = [
64-
...new Set(
65-
details.vulnerabilities.nodes.map(
66-
v => `${v.package.name} (${v.package.ecosystem})`,
67-
),
68-
),
69-
]
76+
const packages = getUniquePackages(details)
7077
return [
7178
body,
7279
'',
@@ -86,13 +93,7 @@ export function getSocketFixPullRequestBody(
8693
const details = ghsaDetails?.get(id)
8794
const item = `- [${id}](${GITHUB_ADVISORIES_URL}/${id})`
8895
if (details) {
89-
const packages = [
90-
...new Set(
91-
details.vulnerabilities.nodes.map(
92-
v => `${v.package.name} (${v.package.ecosystem})`,
93-
),
94-
),
95-
]
96+
const packages = getUniquePackages(details)
9697
return `${item} - ${details.summary} (${joinAnd(packages)})`
9798
}
9899
return item

0 commit comments

Comments
 (0)