Makes License Issues a single table per manifest
This commit is contained in:
@@ -219,7 +219,7 @@ test('addLicensesToSummary() - does not include entire section if no license iss
|
|||||||
expect(text).toEqual('')
|
expect(text).toEqual('')
|
||||||
})
|
})
|
||||||
|
|
||||||
test('addLicensesToSummary() - includes all license issues', () => {
|
test('addLicensesToSummary() - includes all license issues in table', () => {
|
||||||
const licenseIssues = {
|
const licenseIssues = {
|
||||||
forbidden: [createTestChange()],
|
forbidden: [createTestChange()],
|
||||||
unresolved: [createTestChange(), createTestChange()],
|
unresolved: [createTestChange(), createTestChange()],
|
||||||
@@ -230,9 +230,27 @@ test('addLicensesToSummary() - includes all license issues', () => {
|
|||||||
|
|
||||||
const text = core.summary.stringify()
|
const text = core.summary.stringify()
|
||||||
expect(text).toContain('<h2>License Issues</h2>')
|
expect(text).toContain('<h2>License Issues</h2>')
|
||||||
expect(text).toContain('<h3>Incompatible Licenses</h3>')
|
expect(text).toContain('<td>Incompatible License</td>')
|
||||||
expect(text).toContain('<h3>Unknown Licenses</h3>')
|
expect(text).toContain('<td>Invalid SPDX License</td>')
|
||||||
expect(text).toContain('<h3>Invalid SPDX License Definitions</h3>')
|
expect(text).toContain('<td>Unknown License</td>')
|
||||||
|
})
|
||||||
|
|
||||||
|
test('addLicenseToSummary() - adds one table per manifest', () => {
|
||||||
|
const licenseIssues = {
|
||||||
|
forbidden: [
|
||||||
|
createTestChange({manifest: 'package.json'}),
|
||||||
|
createTestChange({manifest: '.github/workflows/test.yml'})
|
||||||
|
],
|
||||||
|
unresolved: [],
|
||||||
|
unlicensed: []
|
||||||
|
}
|
||||||
|
|
||||||
|
summary.addLicensesToSummary(licenseIssues, defaultConfig)
|
||||||
|
|
||||||
|
const text = core.summary.stringify()
|
||||||
|
|
||||||
|
expect(text).toContain('<h4><em>package.json</em></h4>')
|
||||||
|
expect(text).toContain('<h4><em>.github/workflows/test.yml</em></h4>')
|
||||||
})
|
})
|
||||||
|
|
||||||
test('addLicensesToSummary() - does not include specific license type sub-section if nothing is found', () => {
|
test('addLicensesToSummary() - does not include specific license type sub-section if nothing is found', () => {
|
||||||
@@ -245,9 +263,9 @@ test('addLicensesToSummary() - does not include specific license type sub-sectio
|
|||||||
summary.addLicensesToSummary(licenseIssues, defaultConfig)
|
summary.addLicensesToSummary(licenseIssues, defaultConfig)
|
||||||
|
|
||||||
const text = core.summary.stringify()
|
const text = core.summary.stringify()
|
||||||
expect(text).not.toContain('<h3>Incompatible Licenses</h3>')
|
expect(text).not.toContain('<td>Incompatible License</td>')
|
||||||
expect(text).not.toContain('<h3>Unknown Licenses</h3>')
|
expect(text).not.toContain('<td>Unknown License</td>')
|
||||||
expect(text).toContain('<h3>Invalid SPDX License Definitions</h3>')
|
expect(text).toContain('<td>Invalid SPDX License</td>')
|
||||||
})
|
})
|
||||||
|
|
||||||
test('addLicensesToSummary() - includes list of configured allowed licenses', () => {
|
test('addLicensesToSummary() - includes list of configured allowed licenses', () => {
|
||||||
|
|||||||
@@ -57,12 +57,24 @@ const createFullSummary = async (): Promise<void> => {
|
|||||||
createTestChange({
|
createTestChange({
|
||||||
name: 'octoinvader',
|
name: 'octoinvader',
|
||||||
license: 'Non SPDX License'
|
license: 'Non SPDX License'
|
||||||
|
}),
|
||||||
|
createTestChange({
|
||||||
|
name: 'owner/action-1',
|
||||||
|
license: 'XYZ-License',
|
||||||
|
version: 'v1.2.2',
|
||||||
|
manifest: '.github/workflows/action.yml'
|
||||||
})
|
})
|
||||||
],
|
],
|
||||||
unlicensed: [
|
unlicensed: [
|
||||||
createTestChange({
|
createTestChange({
|
||||||
name: 'my-other-dependency',
|
name: 'my-other-dependency',
|
||||||
license: 'No License'
|
license: null
|
||||||
|
}),
|
||||||
|
createTestChange({
|
||||||
|
name: 'owner/action-2',
|
||||||
|
version: 'main',
|
||||||
|
license: null,
|
||||||
|
manifest: '.github/workflows/action.yml'
|
||||||
})
|
})
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|||||||
+4
-1
@@ -14,7 +14,10 @@ import {isSPDXValid, octokitClient} from './utils'
|
|||||||
* @param { { allow?: string[], deny?: string[]}} licenses An object with `allow`/`deny` keys, each containing a list of licenses.
|
* @param { { allow?: string[], deny?: string[]}} licenses An object with `allow`/`deny` keys, each containing a list of licenses.
|
||||||
* @returns {Promise<{Object.<string, Array.<Change>>}} A promise to a Record Object. The keys are strings, unlicensed, unresolved and forbidden. The values are a list of changes
|
* @returns {Promise<{Object.<string, Array.<Change>>}} A promise to a Record Object. The keys are strings, unlicensed, unresolved and forbidden. The values are a list of changes
|
||||||
*/
|
*/
|
||||||
type InvalidLicenseChangeTypes = 'unlicensed' | 'unresolved' | 'forbidden'
|
export type InvalidLicenseChangeTypes =
|
||||||
|
| 'unlicensed'
|
||||||
|
| 'unresolved'
|
||||||
|
| 'forbidden'
|
||||||
export type InvalidLicenseChanges = Record<InvalidLicenseChangeTypes, Changes>
|
export type InvalidLicenseChanges = Record<InvalidLicenseChangeTypes, Changes>
|
||||||
export async function getInvalidLicenseChanges(
|
export async function getInvalidLicenseChanges(
|
||||||
changes: Change[],
|
changes: Change[],
|
||||||
|
|||||||
+29
-24
@@ -1,7 +1,7 @@
|
|||||||
import * as core from '@actions/core'
|
import * as core from '@actions/core'
|
||||||
import {ConfigurationOptions, Changes} from './schemas'
|
import {ConfigurationOptions, Changes} from './schemas'
|
||||||
import {SummaryTableRow} from '@actions/core/lib/summary'
|
import {SummaryTableRow} from '@actions/core/lib/summary'
|
||||||
import {InvalidLicenseChanges} from './licenses'
|
import {InvalidLicenseChanges, InvalidLicenseChangeTypes} from './licenses'
|
||||||
import {groupDependenciesByManifest, getManifestsSet, renderUrl} from './utils'
|
import {groupDependenciesByManifest, getManifestsSet, renderUrl} from './utils'
|
||||||
|
|
||||||
const icons = {
|
const icons = {
|
||||||
@@ -131,6 +131,7 @@ export function addLicensesToSummary(
|
|||||||
}
|
}
|
||||||
|
|
||||||
core.summary.addHeading('License Issues', 2)
|
core.summary.addHeading('License Issues', 2)
|
||||||
|
printLicenseViolations(invalidLicenseChanges)
|
||||||
|
|
||||||
if (config.allow_licenses && config.allow_licenses.length > 0) {
|
if (config.allow_licenses && config.allow_licenses.length > 0) {
|
||||||
core.summary.addQuote(
|
core.summary.addQuote(
|
||||||
@@ -151,40 +152,44 @@ export function addLicensesToSummary(
|
|||||||
`${invalidLicenseChanges.unresolved.length} licenses could not be validated`
|
`${invalidLicenseChanges.unresolved.length} licenses could not be validated`
|
||||||
)
|
)
|
||||||
|
|
||||||
printLicenseViolation(
|
|
||||||
`Incompatible Licenses`,
|
|
||||||
invalidLicenseChanges.forbidden
|
|
||||||
)
|
|
||||||
printLicenseViolation(
|
|
||||||
`Invalid SPDX License Definitions`,
|
|
||||||
invalidLicenseChanges.unresolved
|
|
||||||
)
|
|
||||||
printLicenseViolation(`Unknown Licenses`, invalidLicenseChanges.unlicensed)
|
|
||||||
core.summary.addSeparator()
|
core.summary.addSeparator()
|
||||||
}
|
}
|
||||||
function printLicenseViolation(heading: string, changes: Changes): void {
|
|
||||||
if (changes.length === 0) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
core.summary.addSeparator()
|
const licenseIssueTypes: InvalidLicenseChangeTypes[] = [
|
||||||
core.summary.addHeading(heading, 3)
|
'forbidden',
|
||||||
|
'unresolved',
|
||||||
|
'unlicensed'
|
||||||
|
]
|
||||||
|
|
||||||
const rows: SummaryTableRow[] = []
|
const issueTypeNames: Record<InvalidLicenseChangeTypes, string> = {
|
||||||
const manifests = getManifestsSet(changes)
|
forbidden: 'Incompatible License',
|
||||||
|
unresolved: 'Invalid SPDX License',
|
||||||
|
unlicensed: 'Unknown License'
|
||||||
|
}
|
||||||
|
|
||||||
for (const manifest of manifests) {
|
function printLicenseViolations(changes: InvalidLicenseChanges): void {
|
||||||
core.summary.addHeading(`<em>${manifest}</em>`, 4)
|
const rowsGroupedByManifest: Record<string, SummaryTableRow[]> = {}
|
||||||
|
|
||||||
for (const change of changes.filter(pkg => pkg.manifest === manifest)) {
|
for (const issueType of licenseIssueTypes) {
|
||||||
rows.push([
|
for (const change of changes[issueType]) {
|
||||||
|
if (!rowsGroupedByManifest[change.manifest]) {
|
||||||
|
rowsGroupedByManifest[change.manifest] = []
|
||||||
|
}
|
||||||
|
rowsGroupedByManifest[change.manifest].push([
|
||||||
renderUrl(change.source_repository_url, change.name),
|
renderUrl(change.source_repository_url, change.name),
|
||||||
change.version,
|
change.version,
|
||||||
formatLicense(change.license)
|
formatLicense(change.license),
|
||||||
|
issueTypeNames[issueType]
|
||||||
])
|
])
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
core.summary.addTable([['Package', 'Version', 'License'], ...rows])
|
for (const [manifest, rows] of Object.entries(rowsGroupedByManifest)) {
|
||||||
|
core.summary.addHeading(`<em>${manifest}</em>`, 4)
|
||||||
|
core.summary.addTable([
|
||||||
|
['Package', 'Version', 'License', 'Issue Type'],
|
||||||
|
...rows
|
||||||
|
])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user