From bae9de438d2dd3e1e026922ee3af11d0d9a952f8 Mon Sep 17 00:00:00 2001 From: Timur Shemsedinov Date: Wed, 24 Jan 2024 18:35:05 +0200 Subject: [PATCH] Update report generation PR-URL: https://github.com/HowProgrammingWorks/SelfAssessment/pull/147 --- .github/src/check.js | 37 +++++++++++++++++++------------------ 1 file changed, 19 insertions(+), 18 deletions(-) diff --git a/.github/src/check.js b/.github/src/check.js index 776816b4..69569b6c 100644 --- a/.github/src/check.js +++ b/.github/src/check.js @@ -28,9 +28,15 @@ const LINK = 'https://github.com/' + REPO; const BASE = 'https://img.shields.io/badge/Self_Assessment-skills'; const STYLE = `style=flat-square`; +const codeBlock = (code) => '```\n' + code + '\n```'; + const generateBadge = () => { const color = exitCode === 0 ? '009933' : 'FF3300'; - return `[![Skills](${BASE}-${color}?${STYLE})](${LINK})`; + const img = `${BASE}-${color}?${STYLE}`; + return { + md: `[![Skills](${img})](${LINK})`, + html: `Skills`, + }; }; const UNITS = [ @@ -42,7 +48,6 @@ const UNITS = [ 'Architecture', ]; - const wrongFormat = (msg, file) => { exitCode = 1; console.log(fatal` Wrong file format: ${msg} `); @@ -54,8 +59,6 @@ const warnFixup = (msg, file) => { console.log(fixup` File: ${file} `); }; -const codeBlock = (code) => '```\n' + code + '\n```'; - const loadFile = async (filePath) => { const fileName = path.basename(filePath); const data = await fs.readFile(filePath, 'utf8'); @@ -174,15 +177,12 @@ const getSkills = (data, file, options) => { if (skills.has(skill) && options.unique) { warnFixup(`removed duplicate skill «${skill}» at line ${i + 1}`, file); } else { - if (level) { - out.push(` - ${skill}: ${level}`); - sections[section][skill] = level; - skills.set(skill, level); - } else { - out.push(` - ${skill}`); - sections[section][skill] = ''; - skills.set(skill, ''); - } + let row = ` - ${skill}`; + if (level) row += `: ${level}`; + out.push(row); + const value = level || ''; + sections[section][skill] = value; + skills.set(skill, value); } continue; } @@ -279,16 +279,17 @@ const getTotal = (answered) => { } const badge = generateBadge(); - const badgeCode = codeBlock(badge); + const badgeCode = `${codeBlock(badge.md)}\n\n${codeBlock(badge.html)}`; const report = [ - `## ${TITLE}\n\n${badge}\n\n${badgeCode}\n`, + `## ${TITLE}\n\n${badge.md}\n\n${badgeCode}\n`, ...totals, ...todos, - ].join('\n') + '\n'; - await fs.writeFile(`${PATH}/Profile/REPORT.md`, report); + ]; + const profileReport = report.join('\n') + '\n'; + await fs.writeFile(`${PATH}/Profile/REPORT.md`, profileReport); const template = await loadFile(`${PATH}/.github/src/Templates/README.md`); - const readme = template.replace('$BADGE', badge); + const readme = template.replace('$BADGE', badge.md); await fs.writeFile(`${PATH}/README.md`, readme); console.log('');