2022-11-04 09:05:45 +00:00
|
|
|
import * as core from '@actions/core'
|
|
|
|
|
import {Octokit} from 'octokit'
|
2022-10-26 09:01:43 +00:00
|
|
|
import spdxParse from 'spdx-expression-parse'
|
2022-09-27 12:23:05 +02:00
|
|
|
import {Changes} from './schemas'
|
|
|
|
|
|
|
|
|
|
export function groupDependenciesByManifest(
|
|
|
|
|
changes: Changes
|
|
|
|
|
): Map<string, Changes> {
|
|
|
|
|
const dependencies: Map<string, Changes> = new Map()
|
|
|
|
|
for (const change of changes) {
|
|
|
|
|
const manifestName = change.manifest
|
|
|
|
|
|
|
|
|
|
if (dependencies.get(manifestName) === undefined) {
|
|
|
|
|
dependencies.set(manifestName, [])
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
dependencies.get(manifestName)?.push(change)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return dependencies
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function getManifestsSet(changes: Changes): Set<string> {
|
|
|
|
|
return new Set(changes.flatMap(c => c.manifest))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function renderUrl(url: string | null, text: string): string {
|
|
|
|
|
if (url) {
|
|
|
|
|
return `<a href="${url}">${text}</a>`
|
|
|
|
|
} else {
|
|
|
|
|
return text
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-10-26 09:01:43 +00:00
|
|
|
|
|
|
|
|
export function isSPDXValid(license: string): boolean {
|
|
|
|
|
try {
|
|
|
|
|
spdxParse(license)
|
|
|
|
|
return true
|
|
|
|
|
} catch (_) {
|
|
|
|
|
return false
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-11-04 09:05:45 +00:00
|
|
|
|
|
|
|
|
export function octokitClient(token = 'repo-token'): Octokit {
|
|
|
|
|
return new Octokit({
|
|
|
|
|
auth: core.getInput(token, {required: true})
|
|
|
|
|
})
|
|
|
|
|
}
|