Replace packageurl-js with our own implementation
This commit is contained in:
45
src/utils.ts
45
src/utils.ts
@@ -1,7 +1,6 @@
|
||||
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(
|
||||
@@ -69,47 +68,3 @@ export function octokitClient(token = 'repo-token', required = true): Octokit {
|
||||
|
||||
return new Octokit(opts)
|
||||
}
|
||||
|
||||
export const parsePURL = (purlString: string): PackageURL => {
|
||||
try {
|
||||
return PackageURL.fromString(purlString)
|
||||
} catch (error) {
|
||||
if (
|
||||
(error as Error).message ===
|
||||
`purl is missing the required "name" component.`
|
||||
) {
|
||||
//packageurl-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 fixedPurlString = addTempName(purlString)
|
||||
const purl = PackageURL.fromString(fixedPurlString)
|
||||
purl.name = ''
|
||||
return purl
|
||||
} else if ((error as Error).message === `version must be percent-encoded`) {
|
||||
core.error(
|
||||
`Version must be percent-encoded. Removing version from purl: '${purlString}.`
|
||||
)
|
||||
const fixedPurlString = removeVersion(purlString)
|
||||
const purl = parsePURL(fixedPurlString)
|
||||
purl.version = ''
|
||||
return purl
|
||||
}
|
||||
core.error(`Error parsing purl: ${purlString}`)
|
||||
throw error
|
||||
}
|
||||
}
|
||||
|
||||
export const removeVersion = (purlString: string): string => {
|
||||
// sometimes these errors are actually caused by a final '/', so try removing that first
|
||||
if (purlString.endsWith('/')) {
|
||||
return purlString.substring(0, purlString.length - 1)
|
||||
}
|
||||
const idx = purlString.lastIndexOf('@')
|
||||
return purlString.substring(0, idx)
|
||||
}
|
||||
|
||||
export const addTempName = (purlString: string): string => {
|
||||
if (purlString.endsWith('/')) {
|
||||
return `${purlString}TEMP_NAME`
|
||||
}
|
||||
return `${purlString}/TEMP_NAME`
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user