(args: string[], attempts = 12)
| 2083 | } |
| 2084 | |
| 2085 | function ghWithRetry(args: string[], attempts = 12): string { |
| 2086 | let lastError: unknown; |
| 2087 | for (let attempt = 0; attempt < attempts; attempt += 1) { |
| 2088 | try { |
| 2089 | return gh(args); |
| 2090 | } catch (error) { |
| 2091 | lastError = error; |
| 2092 | const retryKind = ghRetryKind(error); |
| 2093 | if (retryKind === "none" || attempt === attempts - 1) throw error; |
| 2094 | const waitMs = ghRetryWaitMs(retryKind, attempt); |
| 2095 | const retryLabel = |
| 2096 | retryKind === "throttle" ? "GitHub throttled" : "Transient GitHub API failure"; |
| 2097 | console.error( |
| 2098 | `${retryLabel}; retrying ${summarizeGhArgs(args)} in ${Math.round(waitMs / 1000)}s`, |
| 2099 | ); |
| 2100 | if (retryKind === "throttle") { |
| 2101 | maybePublishThrottleHeartbeat({ args, attempt, attempts, waitMs }); |
| 2102 | } |
| 2103 | sleepMs(waitMs); |
| 2104 | } |
| 2105 | } |
| 2106 | throw lastError; |
| 2107 | } |
| 2108 | |
| 2109 | function ghRawWithRetry(args: string[], attempts = 12): string { |
| 2110 | let lastError: unknown; |
no test coverage detected