|
1 | 1 | import * as semver from 'semver';
|
2 | 2 | import type { GithubRepo } from '@mongodb-js/devtools-github-repo';
|
3 | 3 |
|
| 4 | +/** |
| 5 | + * When sending requests via Octokit, a situation can arise where the server closes the connection, |
| 6 | + * but the client still believes it’s open and attempts to write to it, |
| 7 | + * what leads to receiving an EPIPE error from the OS, indicating the connection has already been closed. |
| 8 | + * In such cases, retrying the request can help establish a new, functional connection. |
| 9 | + */ |
| 10 | +async function getFormulaFromRepositoryWithRetry( |
| 11 | + homebrewCore: GithubRepo, |
| 12 | + remainingRetries = 3 |
| 13 | +) { |
| 14 | + try { |
| 15 | + return await homebrewCore.getFileContent('Formula/m/mongosh.rb', 'master'); |
| 16 | + } catch (error: any) { |
| 17 | + if (error.message.includes('EPIPE') && remainingRetries > 0) { |
| 18 | + console.error(error); |
| 19 | + return await getFormulaFromRepositoryWithRetry( |
| 20 | + homebrewCore, |
| 21 | + remainingRetries - 1 |
| 22 | + ); |
| 23 | + } else { |
| 24 | + throw error; |
| 25 | + } |
| 26 | + } |
| 27 | +} |
| 28 | + |
4 | 29 | export async function generateUpdatedFormula(
|
5 | 30 | context: { version: string; sha: string },
|
6 | 31 | homebrewCore: GithubRepo,
|
7 | 32 | isDryRun: boolean
|
8 | 33 | ): Promise<string | null> {
|
9 |
| - const currentFormula = await homebrewCore.getFileContent( |
10 |
| - 'Formula/m/mongosh.rb', |
11 |
| - 'master' |
12 |
| - ); |
| 34 | + const currentFormula = await getFormulaFromRepositoryWithRetry(homebrewCore); |
13 | 35 |
|
14 | 36 | const urlMatch = /url "([^"]+)"/g.exec(currentFormula.content);
|
15 | 37 | const shaMatch = /sha256 "([^"]+)"/g.exec(currentFormula.content);
|
|
0 commit comments