using packageurl-js to parse packages and groups from config

This commit is contained in:
Brandon Teng
2024-04-16 12:44:51 -05:00
parent 061f471b83
commit a318e62c6c
6 changed files with 122 additions and 31 deletions
+19
View File
@@ -1,6 +1,7 @@
import * as core from '@actions/core'
import {Octokit} from 'octokit'
import spdxParse from 'spdx-expression-parse'
import {PackageURL} from 'packageurl-js'
import {Changes} from './schemas'
export function groupDependenciesByManifest(
@@ -68,3 +69,21 @@ export function octokitClient(token = 'repo-token', required = true): Octokit {
return new Octokit(opts)
}
export const parseGroupPURL = (purlString: string): PackageURL | undefined => {
try {
return PackageURL.fromString(purlString)
} catch (error) {
if (
(error as Error).message ===
`purl is missing the required "name" component.`
) {
//package-url-js does not support empty names, so will manually override it for deny-groups
//https://github.com/package-url/packageurl-js/blob/master/src/package-url.js#L216
const purl = PackageURL.fromString(`${purlString}TEMP_NAME`)
purl.name = ''
return purl
}
}
return undefined
}