update licenses pkg and tests

This commit is contained in:
Eli Reisman
2024-06-10 09:51:01 -07:00
parent 2e4eaa490e
commit bbed6f340a
4 changed files with 62 additions and 42 deletions
+7 -12
View File
@@ -1,8 +1,7 @@
import spdxSatisfies from 'spdx-satisfies'
import {Change, Changes} from './schemas'
import {octokitClient} from './utils'
import {parsePURL} from './purl'
import {isValid} from './spdx'
import * as spdx from './spdx'
/**
* Loops through a list of changes, filtering and returning the
@@ -48,7 +47,7 @@ export async function getInvalidLicenseChanges(
const changeAsPackageURL = parsePURL(encodeURI(change.package_url))
// We want to find if the licenseExclussion list contains the PackageURL of the Change
// We want to find if the licenseExclusion list contains the PackageURL of the Change
// If it does, we want to filter it out and therefore return false
// If it doesn't, we want to keep it and therefore return true
if (
@@ -88,15 +87,11 @@ export async function getInvalidLicenseChanges(
} else if (validityCache.get(license) === undefined) {
try {
if (allow !== undefined) {
const found = allow.find(spdxExpression =>
spdxSatisfies(license, spdxExpression)
)
validityCache.set(license, found !== undefined)
const found = spdx.satisfiesAny(license, allow)
validityCache.set(license, found)
} else if (deny !== undefined) {
const found = deny.find(spdxExpression =>
spdxSatisfies(license, spdxExpression)
)
validityCache.set(license, found === undefined)
const found = spdx.satisfiesAny(license, deny)
validityCache.set(license, !found)
}
} catch (err) {
invalidLicenseChanges.unresolved.push(change)
@@ -166,7 +161,7 @@ const setGHLicenses = async (changes: Change[]): Promise<Change[]> => {
// Currently Dependency Graph licenses are truncated to 255 characters
// This possibly makes them invalid spdx ids
const truncatedDGLicense = (license: string): boolean =>
license.length === 255 && !isValid(license)
license.length === 255 && !spdx.isValid(license)
async function groupChanges(
changes: Changes
+14
View File
@@ -8,6 +8,20 @@ export function satisfies(
return spdx.satisfies(candidateExpr, constraintExpr)
}
export function satisfiesAny(
candidateExpr: string,
licenses: string[]
): boolean {
return spdx.satisfiesAny(candidateExpr, licenses)
}
export function satisfiesAll(
candidateExpr: string,
licenses: string[]
): boolean {
return spdx.satisfiesAll(candidateExpr, licenses)
}
// can be a single license or an SPDX expression
export function isValid(spdxExpr: string): boolean {
try {