|
25 | 25 | //
|
26 | 26 | // `DANGER_GITHUB_API_TOKEN=[ENV_ABOVE] yarn danger pr https://github.com/facebook/react/pull/11865
|
27 | 27 |
|
28 |
| -const {markdown, danger} = require('danger'); |
| 28 | +const {markdown, danger, warn} = require('danger'); |
29 | 29 | const fetch = require('node-fetch');
|
30 | 30 |
|
31 | 31 | const {generateResultsArray} = require('./scripts/rollup/stats');
|
@@ -108,18 +108,61 @@ function git(args) {
|
108 | 108 | // Use git locally to grab the commit which represents the place
|
109 | 109 | // where the branches differ
|
110 | 110 | const upstreamRepo = danger.github.pr.base.repo.full_name;
|
| 111 | + if (upstreamRepo !== 'facebook/react') { |
| 112 | + // Exit unless we're running in the main repo |
| 113 | + return; |
| 114 | + } |
| 115 | + |
111 | 116 | const upstreamRef = danger.github.pr.base.ref;
|
112 |
| - await git(`remote add upstream https://github.com/${upstreamRepo}.git`); |
| 117 | + await git(`remote add upstream https://github.com/facebook/react.git`); |
113 | 118 | await git('fetch upstream');
|
114 |
| - const mergeBaseCommit = await git(`merge-base HEAD upstream/${upstreamRef}`); |
| 119 | + const baseCommit = await git(`merge-base HEAD upstream/${upstreamRef}`); |
| 120 | + |
| 121 | + let resultsResponse = null; |
| 122 | + try { |
| 123 | + let baseCIBuildId = null; |
| 124 | + const statusesResponse = await fetch( |
| 125 | + `https://api.github.com/repos/facebook/react/commits/${baseCommit}/statuses` |
| 126 | + ); |
| 127 | + const statuses = await statusesResponse.json(); |
| 128 | + for (let i = 0; i < statuses.length; i++) { |
| 129 | + const status = statuses[i]; |
| 130 | + if (status.context === 'ci/circleci' && status.state === 'success') { |
| 131 | + baseCIBuildId = /\/facebook\/react\/([0-9]+)/.exec( |
| 132 | + status.target_url |
| 133 | + )[1]; |
| 134 | + } |
| 135 | + } |
| 136 | + |
| 137 | + if (baseCIBuildId === null) { |
| 138 | + warn(`Base commit is broken: ${baseCommit}`); |
| 139 | + return; |
| 140 | + } |
115 | 141 |
|
116 |
| - const commitURL = sha => |
117 |
| - `http://react.zpao.com/builds/master/_commits/${sha}/results.json`; |
118 |
| - const response = await fetch(commitURL(mergeBaseCommit)); |
| 142 | + const baseArtifactsInfoResponse = await fetch( |
| 143 | + `https://circleci.com/api/v1.1/project/github/facebook/react/${baseCIBuildId}/artifacts` |
| 144 | + ); |
| 145 | + const baseArtifactsInfo = await baseArtifactsInfoResponse.json(); |
| 146 | + |
| 147 | + for (let i = 0; i < baseArtifactsInfo.length; i++) { |
| 148 | + const info = baseArtifactsInfo[i]; |
| 149 | + if (info.path === 'home/circleci/project/scripts/results.json') { |
| 150 | + resultsResponse = await fetch(info.url); |
| 151 | + } |
| 152 | + } |
| 153 | + } catch (error) { |
| 154 | + warn(`Failed to fetch build artifacts for base commit: ${baseCommit}`); |
| 155 | + return; |
| 156 | + } |
| 157 | + |
| 158 | + if (resultsResponse === null) { |
| 159 | + warn(`Could not find build artifacts for base commit: ${baseCommit}`); |
| 160 | + return; |
| 161 | + } |
119 | 162 |
|
120 | 163 | // Take the JSON of the build response and
|
121 | 164 | // make an array comparing the results for printing
|
122 |
| - const previousBuildResults = await response.json(); |
| 165 | + const previousBuildResults = await resultsResponse.json(); |
123 | 166 | const results = generateResultsArray(
|
124 | 167 | currentBuildResults,
|
125 | 168 | previousBuildResults
|
@@ -212,7 +255,7 @@ function git(args) {
|
212 | 255 | <details>
|
213 | 256 | <summary>Details of bundled changes.</summary>
|
214 | 257 |
|
215 |
| - <p>Comparing: ${mergeBaseCommit}...${danger.github.pr.head.sha}</p> |
| 258 | + <p>Comparing: ${baseCommit}...${danger.github.pr.head.sha}</p> |
216 | 259 |
|
217 | 260 |
|
218 | 261 | ${allTables.join('\n')}
|
|
0 commit comments