7
7
8
8
'use strict' ;
9
9
10
+ // Hi, if this is your first time editing/reading a Dangerfile, here's a summary:
11
+ // It's a JS runtime which helps you provide continuous feedback inside GitHub.
12
+ //
13
+ // You can see the docs here: http://danger.systems/js/
14
+ //
15
+ // If you want to test changes Danger, I'd recommend checking out an existing PR
16
+ // and then running the `danger pr` command.
17
+ //
18
+ // You'll need a GitHub token, you can re-use this one:
19
+ //
20
+ // e622517d9f1136ea8900 07c6373666312cdfaa69
21
+ //
22
+ // (Just remove the space)
23
+ //
24
+ // So, for example:
25
+ //
26
+ // `DANGER_GITHUB_API_TOKEN=[ENV_ABOVE] yarn danger pr https://github.com/facebook/react/pull/11865
27
+
10
28
const { markdown, danger} = require ( 'danger' ) ;
11
29
const fetch = require ( 'node-fetch' ) ;
12
30
13
31
const { generateResultsArray} = require ( './scripts/rollup/stats' ) ;
14
32
const { readFileSync} = require ( 'fs' ) ;
33
+ const { exec} = require ( 'child_process' ) ;
15
34
16
35
const currentBuildResults = JSON . parse (
17
36
readFileSync ( './scripts/rollup/results.json' )
@@ -54,13 +73,40 @@ function setBoldness(row, isBold) {
54
73
}
55
74
}
56
75
57
- // Grab the results.json before we ran CI via the GH API
58
- // const baseMerge = danger.github.pr.base.sha
59
- const parentOfOldestCommit = danger . git . commits [ 0 ] . parents [ 0 ] ;
60
- const commitURL = sha =>
61
- `http://react.zpao.com/builds/master/_commits/${ sha } /results.json` ;
76
+ /**
77
+ * Gets the commit that represents the merge between the current branch
78
+ * and master.
79
+ */
80
+ function getMergeBase ( ) {
81
+ return git ( 'merge-base HEAD origin/master' ) ;
82
+ }
62
83
63
- fetch ( commitURL ( parentOfOldestCommit ) ) . then ( async response => {
84
+ /**
85
+ * Gets the commit that represents the merge between the current branch
86
+ * and master.
87
+ */
88
+ function git ( args ) {
89
+ return new Promise ( res => {
90
+ exec ( 'git ' + args , ( err , stdout , stderr ) => {
91
+ if ( err ) {
92
+ throw err ;
93
+ } else {
94
+ res ( stdout . trim ( ) ) ;
95
+ }
96
+ } ) ;
97
+ } ) ;
98
+ }
99
+
100
+ ( async function ( ) {
101
+ // Use git locally to grab the commit which represents the place
102
+ // where the branches differ
103
+ const mergeBaseCommit = await getMergeBase ( ) ;
104
+ const commitURL = sha =>
105
+ `http://react.zpao.com/builds/master/_commits/${ sha } /results.json` ;
106
+ const response = await fetch ( commitURL ( mergeBaseCommit ) ) ;
107
+
108
+ // Take the JSON of the build response and
109
+ // make an array comparing the results for printing
64
110
const previousBuildResults = await response . json ( ) ;
65
111
const results = generateResultsArray (
66
112
currentBuildResults ,
@@ -74,6 +120,7 @@ fetch(commitURL(parentOfOldestCommit)).then(async response => {
74
120
Math . abs ( r . prevFileSizeChange ) > percentToWarrentShowing ||
75
121
Math . abs ( r . prevGzipSizeChange ) > percentToWarrentShowing
76
122
)
123
+
77
124
. map ( r => r . packageName ) ;
78
125
79
126
if ( packagesToShow . length ) {
@@ -152,16 +199,16 @@ fetch(commitURL(parentOfOldestCommit)).then(async response => {
152
199
}
153
200
154
201
const summary = `
155
- <details>
156
- <summary>Details of bundled changes.</summary>
202
+ <details>
203
+ <summary>Details of bundled changes.</summary>
157
204
158
- <p>Comparing: ${ parentOfOldestCommit } ...${ danger . github . pr . head . sha } </p>
205
+ <p>Comparing: ${ mergeBaseCommit } ...${ danger . github . pr . head . sha } </p>
159
206
160
207
161
- ${ allTables . join ( '\n' ) }
208
+ ${ allTables . join ( '\n' ) }
162
209
163
- </details>
164
- ` ;
210
+ </details>
211
+ `;
165
212
markdown ( summary ) ;
166
213
}
167
- } ) ;
214
+ } ) ( ) ;
0 commit comments