@@ -24,6 +24,25 @@ function readPRFile(path) {
24
24
return git . show ( [ `pr:${ path } ` ] ) ;
25
25
}
26
26
27
+ /**
28
+ * Returns the relative paths of all files changed in the PR.
29
+ *
30
+ * @returns {Promise<string[]> }
31
+ */
32
+ const getChangedFiles = async ( ) => {
33
+ // Determine the merge base between master and the PR branch.
34
+ // If files changed in master since PR was branched they would show in the diff otherwise.
35
+ // https://stackoverflow.com/questions/25071579/list-all-files-changed-in-a-pull-request-in-git-github
36
+ const mergeBase = await git . raw ( [ 'merge-base' , 'pr' , 'HEAD' ] ) ;
37
+ const result = await git . diff ( [ '--name-only' , '--no-renames' , 'pr' , mergeBase ] ) ;
38
+ return ( result || '' ) . split ( / \r ? \n / g) ;
39
+ } ;
40
+
41
+ const getChangedMinifiedFiles = async ( ) => {
42
+ const changed = await getChangedFiles ( ) ;
43
+ return changed . filter ( file => file . endsWith ( '.min.js' ) ) ;
44
+ } ;
45
+
27
46
// https://stackoverflow.com/questions/15900485/correct-way-to-convert-size-in-bytes-to-kb-mb-gb-in-javascript
28
47
const formatBytes = ( bytes , decimals = 2 ) => {
29
48
if ( bytes === 0 ) return '0 Bytes' ;
@@ -64,11 +83,6 @@ const getSummary = (rows, totalMasterFileSize, totalFileSize) => {
64
83
return `A total of ${ numFiles } file${ maybeS } have changed, with a combined diff of ${ byteDiff } (${ percentDiff } ).` ;
65
84
}
66
85
67
- const getChangedMinifiedFiles = async ( ) => {
68
- const result = await git . diff ( [ '--name-only' , '--no-renames' , 'pr' , 'HEAD' ] ) ;
69
- return ( result || '' ) . split ( / \r ? \n / g) . filter ( file => file . endsWith ( '.min.js' ) ) ;
70
- } ;
71
-
72
86
const run = async ( ) => {
73
87
const minified = await getChangedMinifiedFiles ( ) ;
74
88
0 commit comments