Skip to content

Commit

Permalink
Dangerfile: Fixed how changed files are determined (#2757)
Browse files Browse the repository at this point in the history
  • Loading branch information
RunDevelopment committed Feb 12, 2021
1 parent cf354ef commit 0feb266
Showing 1 changed file with 19 additions and 5 deletions.
24 changes: 19 additions & 5 deletions dangerfile.js
Expand Up @@ -24,6 +24,25 @@ function readPRFile(path) {
return git.show([`pr:${path}`]);
}

/**
* Returns the relative paths of all files changed in the PR.
*
* @returns {Promise<string[]>}
*/
const getChangedFiles = async () => {
// Determine the merge base between master and the PR branch.
// If files changed in master since PR was branched they would show in the diff otherwise.
// https://stackoverflow.com/questions/25071579/list-all-files-changed-in-a-pull-request-in-git-github
const mergeBase = await git.raw(['merge-base', 'pr', 'HEAD']);
const result = await git.diff(['--name-only', '--no-renames', 'pr', mergeBase]);
return (result || '').split(/\r?\n/g);
};

const getChangedMinifiedFiles = async () => {
const changed = await getChangedFiles();
return changed.filter(file => file.endsWith('.min.js'));
};

// https://stackoverflow.com/questions/15900485/correct-way-to-convert-size-in-bytes-to-kb-mb-gb-in-javascript
const formatBytes = (bytes, decimals = 2) => {
if (bytes === 0) return '0 Bytes';
Expand Down Expand Up @@ -64,11 +83,6 @@ const getSummary = (rows, totalMasterFileSize, totalFileSize) => {
return `A total of ${numFiles} file${maybeS} have changed, with a combined diff of ${byteDiff} (${percentDiff}).`;
}

const getChangedMinifiedFiles = async () => {
const result = await git.diff(['--name-only', '--no-renames', 'pr', 'HEAD']);
return (result || '').split(/\r?\n/g).filter(file => file.endsWith('.min.js'));
};

const run = async () => {
const minified = await getChangedMinifiedFiles();

Expand Down

0 comments on commit 0feb266

Please sign in to comment.