mirror of
https://github.com/facebook/react.git
synced 2025-11-01 09:12:30 +00:00
Highlight production bundles in bold in the Danger integration comment (#12054)
* update Danger integration comments * update Danger integration comments * revised codes for unconditional call * update setBoldness parameter
This commit is contained in:
+33
-17
@@ -36,14 +36,24 @@ function generateMDTable(headers, body) {
|
||||
* Generates a user-readable string from a percentage change
|
||||
* @param {string[]} headers
|
||||
*/
|
||||
function emojiPercent(change) {
|
||||
if (change > 0) {
|
||||
function addPercent(change, includeEmoji) {
|
||||
if (change > 0 && includeEmoji) {
|
||||
return `:small_red_triangle:+${change}%`;
|
||||
} else if (change <= 0) {
|
||||
} else if (change > 0) {
|
||||
return `+${change}%`;
|
||||
} else {
|
||||
return `${change}%`;
|
||||
}
|
||||
}
|
||||
|
||||
function setBoldness(row, isBold) {
|
||||
if (isBold) {
|
||||
return row.map(element => `**${element}**`);
|
||||
} else {
|
||||
return row;
|
||||
}
|
||||
}
|
||||
|
||||
// Grab the results.json before we ran CI via the GH API
|
||||
// const baseMerge = danger.github.pr.base.sha
|
||||
const parentOfOldestCommit = danger.git.commits[0].parents[0];
|
||||
@@ -80,8 +90,8 @@ fetch(commitURL(parentOfOldestCommit)).then(async response => {
|
||||
reactProd.prevFileSizeChange !== 0 ||
|
||||
reactProd.prevGzipSizeChange !== 0
|
||||
) {
|
||||
const changeSize = emojiPercent(reactProd.prevFileSizeChange);
|
||||
const changeGzip = emojiPercent(reactProd.prevGzipSizeChange);
|
||||
const changeSize = addPercent(reactProd.prevFileSizeChange, true);
|
||||
const changeGzip = addPercent(reactProd.prevGzipSizeChange, true);
|
||||
markdown(`React: size: ${changeSize}, gzip: ${changeGzip}`);
|
||||
}
|
||||
}
|
||||
@@ -94,8 +104,8 @@ fetch(commitURL(parentOfOldestCommit)).then(async response => {
|
||||
reactDOMProd.prevFileSizeChange !== 0 ||
|
||||
reactDOMProd.prevGzipSizeChange !== 0
|
||||
) {
|
||||
const changeSize = emojiPercent(reactDOMProd.prevFileSizeChange);
|
||||
const changeGzip = emojiPercent(reactDOMProd.prevGzipSizeChange);
|
||||
const changeSize = addPercent(reactDOMProd.prevFileSizeChange, true);
|
||||
const changeGzip = addPercent(reactDOMProd.prevGzipSizeChange, true);
|
||||
markdown(`ReactDOM: size: ${changeSize}, gzip: ${changeGzip}`);
|
||||
}
|
||||
}
|
||||
@@ -120,16 +130,22 @@ fetch(commitURL(parentOfOldestCommit)).then(async response => {
|
||||
'ENV',
|
||||
];
|
||||
|
||||
const mdRows = changedFiles.map(r => [
|
||||
r.filename,
|
||||
emojiPercent(r.prevFileSizeChange),
|
||||
emojiPercent(r.prevGzipSizeChange),
|
||||
r.prevSize,
|
||||
r.prevFileSize,
|
||||
r.prevGzip,
|
||||
r.prevGzipSize,
|
||||
r.bundleType,
|
||||
]);
|
||||
const mdRows = changedFiles.map(r => {
|
||||
const isProd = r.bundleType.includes('PROD');
|
||||
return setBoldness(
|
||||
[
|
||||
r.filename,
|
||||
addPercent(r.prevFileSizeChange, isProd),
|
||||
addPercent(r.prevGzipSizeChange, isProd),
|
||||
r.prevSize,
|
||||
r.prevFileSize,
|
||||
r.prevGzip,
|
||||
r.prevGzipSize,
|
||||
r.bundleType,
|
||||
],
|
||||
isProd
|
||||
);
|
||||
});
|
||||
|
||||
allTables.push(`\n## ${name}`);
|
||||
allTables.push(generateMDTable(mdHeaders, mdRows));
|
||||
|
||||
Reference in New Issue
Block a user