Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
charliegerard committed Nov 28, 2023
1 parent 5cf2308 commit 10c8fde
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 11 deletions.
18 changes: 12 additions & 6 deletions lib/commands/info/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -202,24 +202,30 @@ async function fetchPackageData (pkgName, pkgVersion, { includeAllIssues }, spin
*/
function formatPackageIssuesDetails (packageData, outputMarkdown) {
const issueDetails = packageData.filter(d => d.value?.severity === 'high' || d.value?.severity === 'critical')
const uniqueIssues = issueDetails.reduce((/** @type {{ [key: string]: number }} */ acc, issue) => {

const uniqueIssues = issueDetails.reduce((/** @type {{ [key: string]: {count: Number, label: string | undefined} }} */ acc, issue) => {
const { type } = issue
if (type) {
if (!acc[type]) {
acc[type] = 1
acc[type] = {
label: issue.value?.label,
count: 1
}
} else {
acc[type]++
// @ts-ignore
acc[type].count += 1
}
}
return acc
}, {})

const format = new ChalkOrMarkdown(!!outputMarkdown)
return Object.keys(uniqueIssues).map(issue => {
const issueWithLink = format.hyperlink(`${issue}`, `https://socket.dev/npm/issue/${issue}`, { fallbackToUrl: true })
if (uniqueIssues[issue] === 1) {
const issueWithLink = format.hyperlink(`${uniqueIssues[issue]?.label}`, `https://socket.dev/npm/issue/${issue}`, { fallbackToUrl: true })
if (uniqueIssues[issue]?.count === 1) {
return console.log(`- ${issueWithLink}`)
}
return console.log(`- ${issueWithLink}: ${uniqueIssues[issue]}`)
return console.log(`- ${issueWithLink}: ${uniqueIssues[issue]?.count}`)
})
}

Expand Down
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@
"dependencies": {
"@apideck/better-ajv-errors": "^0.3.6",
"@socketsecurity/config": "^2.0.0",
"@socketsecurity/sdk": "^0.7.2",
"@socketsecurity/sdk": "^0.7.3",
"chalk": "^5.1.2",
"globby": "^13.1.3",
"hpagent": "^1.2.0",
Expand Down

0 comments on commit 10c8fde

Please sign in to comment.