Skip to content

Commit

Permalink
Highlight production bundles in bold in the Danger integration comment (
Browse files Browse the repository at this point in the history
#12054)

* update Danger integration comments

* update Danger integration comments

* revised codes for unconditional call

* update setBoldness parameter
  • Loading branch information
clairecliu authored and gaearon committed Jan 19, 2018
1 parent 97e2911 commit 4ca7855
Showing 1 changed file with 33 additions and 17 deletions.
50 changes: 33 additions & 17 deletions dangerfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down Expand Up @@ -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}`);
}
}
Expand All @@ -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}`);
}
}
Expand All @@ -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));
Expand Down

0 comments on commit 4ca7855

Please sign in to comment.