Skip to content

Highlight production bundles in bold in the Danger integration comment #12054

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jan 19, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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