|
1 | 1 | const gh = require("parse-github-url") |
2 | 2 | const path = require("path") |
3 | 3 | const encodeUrl = require("encodeurl") |
| 4 | +const promiseRetry = require("promise-retry") |
4 | 5 |
|
5 | 6 | const { getCache } = require("gatsby/dist/utils/get-cache") |
6 | 7 | const { createRemoteFileNode } = require("gatsby-source-filesystem") |
@@ -215,31 +216,32 @@ const fetchScmInfo = async (scmUrl, artifactId, labels) => { |
215 | 216 | } |
216 | 217 | }` |
217 | 218 |
|
218 | | - let body = undefined |
219 | | - let count = 0 |
220 | | - |
221 | 219 | // We sometimes get bad results back from the git API where json() is null, so do a bit of retrying |
222 | | - while (!body?.data && count < 3) { |
223 | | - count++ |
224 | | - const res = await fetch("https://api.github.com/graphql", { |
225 | | - method: "POST", |
226 | | - body: JSON.stringify({ query }), |
227 | | - headers: { |
228 | | - Authorization: `Bearer ${accessToken}`, |
229 | | - }, |
230 | | - }) |
231 | | - body = await res.json() |
232 | | - if (!body?.data) { |
233 | | - console.warn( |
234 | | - "Retrying GitHub fetch for", |
235 | | - artifactId, |
236 | | - "- response is", |
237 | | - body |
238 | | - ) |
239 | | - } |
240 | | - } |
| 220 | + const body = await promiseRetry( |
| 221 | + async () => { |
| 222 | + const res = await fetch("https://api.github.com/graphql", { |
| 223 | + method: "POST", |
| 224 | + body: JSON.stringify({ query }), |
| 225 | + headers: { |
| 226 | + Authorization: `Bearer ${accessToken}`, |
| 227 | + }, |
| 228 | + }) |
| 229 | + const ghBody = await res.json() |
| 230 | + if (!ghBody?.data) { |
| 231 | + throw Error( |
| 232 | + `Unsuccessful GitHub fetch for ${artifactId} - response is ${ghBody}` |
| 233 | + ) |
| 234 | + } |
| 235 | + return ghBody |
| 236 | + }, |
| 237 | + { retries: 4, minTimeout: 4 * 1000 } |
| 238 | + ).catch(e => { |
| 239 | + // Do not break the build for this, warn and carry on |
| 240 | + console.warn(e) |
| 241 | + return undefined |
| 242 | + }) |
241 | 243 |
|
242 | | - if (!body?.data && !body?.data?.repository) { |
| 244 | + if (body?.data && !body?.data?.repository) { |
243 | 245 | console.warn("Strange artifact for ", artifactId, "- response is", body) |
244 | 246 | } |
245 | 247 |
|
|
0 commit comments