grafana/scripts/levitate-parse-json-report.js
Esteban Beltran ea243b536c
Levitate: fix markdown diff format (#81477)
* Add some fake breaking changes

* try to generate another breaking chnage

* Keep trying

* Update levitate script

* Add fake breaking changes

* Use latest

* Strip ansi

* Test

* Remove ansi stripping

* ClearAnsi again

* another regex

* Revert some changes used for testing

* Rename function

* Fix indentation in levitate workflow

* Remove test breaking changes

* Remove breaking changes

* Update actions

* Trigger breaking change

* restore file
2024-02-02 09:19:30 +01:00

32 lines
816 B
JavaScript

const fs = require('fs');
const data = JSON.parse(fs.readFileSync('data.json', 'utf8'));
function stripAnsi(str) {
return str.replace(/\x1b\[[0-9;]*m/g, '');
}
const printSection = (title, items) => {
let output = `<h4>${title}</h4>`;
items.forEach((item) => {
const language = item.declaration ? 'typescript' : 'diff';
const code = item.declaration ? item.declaration : stripAnsi(item.diff);
output += `<b>${item.name}</b><br>\n`;
output += `<sub>${item.location}</sub><br>\n`;
output += `<pre lang="${language}">\n${code}\n</pre><br>\n`;
});
return output;
};
let markdown = '';
if (data.removals.length > 0) {
markdown += printSection('Removals', data.removals);
}
if (data.changes.length > 0) {
markdown += printSection('Changes', data.changes);
}
console.log(markdown);