From 9eb5825e36d1b175bc97bdaf4fea822094d78bb0 Mon Sep 17 00:00:00 2001 From: "Ch. Szandor Knapp" Date: Wed, 22 Nov 2023 11:19:45 +0100 Subject: [PATCH] feat: better table format --- scripts/ci/parse-scan-results.js | 29 +++++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/scripts/ci/parse-scan-results.js b/scripts/ci/parse-scan-results.js index 96aa5eb..3b82335 100644 --- a/scripts/ci/parse-scan-results.js +++ b/scripts/ci/parse-scan-results.js @@ -58,11 +58,32 @@ async function createGithubTable(jsonFilePath) { const dataArray = JSON.parse(jsonData); const flattenedData = flattenJsonData(dataArray); - // Generating headers from the keys of the first object in flattenedData - const headers = Object.keys(flattenedData[0]).map(key => ({ data: key, header: true })); + // Filtering out unwanted headers and transforming ruleName + const headers = Object.keys(flattenedData[0]).reduce( + (acc, key) => { + if (!['endLine', 'endColumn', 'url'].includes(key)) { + acc.push({ data: key, header: true }); + } + return acc; + }, + [{ data: ':x:', header: true }], + ); // Adding extra column for red X - // Generating table rows from flattenedData - const tableRows = flattenedData.map(row => Object.values(row).map(cell => cell.toString())); + // Generating table rows + const tableRows = flattenedData.map(row => { + const rowValues = Object.entries(row).reduce( + (acc, [key, value]) => { + if (key === 'ruleName') { + acc.push(`[${value}](${row.url})`); // Transforming ruleName into a Markdown link + } else if (!['endLine', 'endColumn', 'url'].includes(key)) { + acc.push(value.toString()); + } + return acc; + }, + [':x:'], + ); // Adding red X in each row + return rowValues; + }); // Creating the GitHub table await core.summary