99
1010'use strict' ;
1111
12- const { danger, markdown, schedule } = require ( 'danger' ) ;
12+ const { markdown} = require ( 'danger' ) ;
13+ const fetch = require ( 'node-fetch' ) ;
1314
14- const { resultsHeaders, generateResultsArray, currentBuildResults } = require ( './scripts/rollup/stats' ) ;
15+ const {
16+ resultsHeaders,
17+ generateResultsArray,
18+ } = require ( './scripts/rollup/stats' ) ;
19+ const currentBuildResults = require ( './scripts/rollup/results.json' ) ;
1520
1621/**
1722 * Generates a Markdown table
18- * @param {string[] } headers
19- * @param {string[][] } body
23+ * @param {string[] } headers
24+ * @param {string[][] } body
2025 */
2126function generateMDTable ( headers , body ) {
2227 const tableHeaders = [
23- headers . join ( ' | ' ) ,
28+ headers . join ( ' | ' ) ,
2429 headers . map ( ( ) => ' --- ' ) . join ( ' | ' ) ,
2530 ] ;
2631
@@ -29,18 +34,19 @@ function generateMDTable(headers, body) {
2934}
3035
3136// Grab the results.json before we ran CI via the GH API
32- const getJSON = danger . github . utils
33- . fileContents ( 'scripts/rollup/results.json' ) ;
34-
35- // @bug See https://github.com/danger/danger-js/issues/443
36- schedule ( getJSON ) ;
37- getJSON . then ( APIPreviousBuildResults => {
38- const previousBuildResults = JSON . parse ( APIPreviousBuildResults ) ;
39- const results = generateResultsArray ( currentBuildResults , previousBuildResults ) ;
40-
41- markdown ( '### Bundle Changes:\n' ) ;
42- // const percentToWarrentShowing = 0.1
43- // const onlyResultsToShow = results.filter(f => Math.abs(f[3]) > percentToWarrentShowing);
44-
45- markdown ( generateMDTable ( resultsHeaders , results ) ) ;
46- } ) ;
37+ fetch ( 'http://react.zpao.com/builds/master/latest/results.json' ) . then (
38+ async response => {
39+ const previousBuildResults = await response . json ( ) ;
40+ const results = generateResultsArray (
41+ currentBuildResults ,
42+ previousBuildResults
43+ ) ;
44+
45+ markdown ( '### Bundle Changes:\n' ) ;
46+ const percentToWarrentShowing = 1
47+ const onlyResultsToShow = results . filter ( f => Math . abs ( f [ 3 ] ) > percentToWarrentShowing || Math . abs ( f [ 7 ] ) ) ;
48+ const groupBy
49+
50+ markdown ( generateMDTable ( resultsHeaders , results ) ) ;
51+ }
52+ ) ;
0 commit comments