diff --git a/dist/index.js b/dist/index.js index ac489c3..0664b9d 100644 --- a/dist/index.js +++ b/dist/index.js @@ -126028,10 +126028,11 @@ class CopyleftPolicyCheck extends policy_check_1.PolicyCheck { if (components.length === 0) return undefined; const headers = ['Component', 'Version', 'License', 'URL', 'Copyleft']; + const centeredColumns = [4]; const rows = []; components.forEach(component => { component.licenses.forEach(license => { - const copyleftIcon = license_utils_1.licenseUtil.isCopyLeft(license.spdxid?.trim().toLowerCase()) ? ':x:' : ' '; + const copyleftIcon = license_utils_1.licenseUtil.isCopyLeft(license.spdxid?.trim().toLowerCase()) ? 'YES' : 'NO'; rows.push([ component.purl, component.version, @@ -126041,7 +126042,7 @@ class CopyleftPolicyCheck extends policy_check_1.PolicyCheck { ]); }); }); - return `### Copyleft licenses \n ${(0, markdown_utils_1.generateTable)(headers, rows)}`; + return `### Copyleft licenses \n ${(0, markdown_utils_1.generateTable)(headers, rows, centeredColumns)}`; } artifactPolicyFileName() { return 'policy-check-copyleft-results.md'; @@ -126556,12 +126557,13 @@ async function generateJobSummary(scannerResults, policies) { }; const LicensesTable = (items) => { const HEADERS = ['License', 'Copyleft', 'URL']; + const centeredColumns = [1]; const ROWS = []; items.forEach(l => { - const copyleftIcon = l.copyleft ? ':x:' : ' '; + const copyleftIcon = l.copyleft ? 'YES' : 'NO'; ROWS.push([l.spdxid, copyleftIcon, `${license_utils_1.licenseUtil.getOSADL(l?.spdxid) || ''}`]); }); - return (0, markdown_utils_1.generateTable)(HEADERS, ROWS); + return (0, markdown_utils_1.generateTable)(HEADERS, ROWS, centeredColumns); }; const PoliciesTable = (items) => { const HEADERS = ['Policy', 'Status', 'Details']; @@ -127090,11 +127092,23 @@ exports.licenseUtil = new LicenseUtil(); */ Object.defineProperty(exports, "__esModule", ({ value: true })); exports.generateTable = void 0; -const generateTable = (headers, rows) => { +const generateTable = (headers, rows, centeredColumns) => { const COL_SEP = ' | '; + const centeredColumnMapper = new Set(); + if (centeredColumns) + centeredColumns.forEach(c => centeredColumnMapper.add(c)); + const rowSeparator = COL_SEP + + headers + .map((header, index) => { + if (!centeredColumns) + return '-'; + return centeredColumnMapper.has(index) ? ':-:' : '-'; + }) + .join(COL_SEP) + + COL_SEP; return ` ${COL_SEP} ${headers.join(COL_SEP)} ${COL_SEP} - ${COL_SEP + new Array(headers.length).fill('-').join(COL_SEP) + COL_SEP} + ${rowSeparator} ${rows.map(row => COL_SEP + row.join(COL_SEP) + COL_SEP).join('\n')} `; }; diff --git a/src/main.ts b/src/main.ts index 1c85383..aa6794e 100644 --- a/src/main.ts +++ b/src/main.ts @@ -29,7 +29,7 @@ import * as outputs from './app.output'; import { scanService, uploadResults } from './services/scan.service'; import { policyManager } from './policies/policy.manager'; -import { licenseUtil } from './utils/license.utils'; + /** * The main function for the action. * @returns {Promise} Resolves when the action is complete. diff --git a/src/policies/copyleft-policy-check.ts b/src/policies/copyleft-policy-check.ts index f6a861f..55967b7 100644 --- a/src/policies/copyleft-policy-check.ts +++ b/src/policies/copyleft-policy-check.ts @@ -26,8 +26,6 @@ import { CHECK_NAME } from '../app.config'; import { PolicyCheck } from './policy-check'; import { Component, getComponents } from '../services/result.service'; import { generateTable } from '../utils/markdown.utils'; -import * as core from '@actions/core'; -import { context } from '@actions/github'; import { licenseUtil } from '../utils/license.utils'; /** @@ -103,11 +101,12 @@ export class CopyleftPolicyCheck extends PolicyCheck { if (components.length === 0) return undefined; const headers = ['Component', 'Version', 'License', 'URL', 'Copyleft']; + const centeredColumns = [4]; const rows: string[][] = []; components.forEach(component => { component.licenses.forEach(license => { - const copyleftIcon = licenseUtil.isCopyLeft(license.spdxid?.trim().toLowerCase()) ? ':x:' : ' '; + const copyleftIcon = licenseUtil.isCopyLeft(license.spdxid?.trim().toLowerCase()) ? 'YES' : 'NO'; rows.push([ component.purl, component.version, @@ -117,7 +116,7 @@ export class CopyleftPolicyCheck extends PolicyCheck { ]); }); }); - return `### Copyleft licenses \n ${generateTable(headers, rows)}`; + return `### Copyleft licenses \n ${generateTable(headers, rows, centeredColumns)}`; } artifactPolicyFileName(): string { diff --git a/src/services/report.service.ts b/src/services/report.service.ts index a1086c0..2d68cf3 100644 --- a/src/services/report.service.ts +++ b/src/services/report.service.ts @@ -79,13 +79,14 @@ export async function generateJobSummary(scannerResults: ScannerResults, policie const LicensesTable = (items: License[]): string => { const HEADERS: string[] = ['License', 'Copyleft', 'URL']; + const centeredColumns = [1]; const ROWS: string[][] = []; items.forEach(l => { - const copyleftIcon = l.copyleft ? ':x:' : ' '; + const copyleftIcon = l.copyleft ? 'YES' : 'NO'; ROWS.push([l.spdxid, copyleftIcon, `${licenseUtil.getOSADL(l?.spdxid) || ''}`]); }); - return generateTable(HEADERS, ROWS); + return generateTable(HEADERS, ROWS, centeredColumns); }; const PoliciesTable = (items: PolicyCheck[]): string => { diff --git a/src/utils/markdown.utils.ts b/src/utils/markdown.utils.ts index 5daf7ad..e32e15d 100644 --- a/src/utils/markdown.utils.ts +++ b/src/utils/markdown.utils.ts @@ -21,12 +21,24 @@ THE SOFTWARE. */ -export const generateTable = (headers: string[], rows: string[][]): string => { +export const generateTable = (headers: string[], rows: string[][], centeredColumns?: number[]): string => { const COL_SEP = ' | '; + const centeredColumnMapper: Set = new Set(); + if (centeredColumns) centeredColumns.forEach(c => centeredColumnMapper.add(c)); + + const rowSeparator = + COL_SEP + + headers + .map((header, index) => { + if (!centeredColumns) return '-'; + return centeredColumnMapper.has(index) ? ':-:' : '-'; + }) + .join(COL_SEP) + + COL_SEP; return ` ${COL_SEP} ${headers.join(COL_SEP)} ${COL_SEP} - ${COL_SEP + new Array(headers.length).fill('-').join(COL_SEP) + COL_SEP} + ${rowSeparator} ${rows.map(row => COL_SEP + row.join(COL_SEP) + COL_SEP).join('\n')} `; };