( spawner: typeof execa, suppressOutput = false )
| 19 | // We implement these as function factories to make unit testing easier. |
| 20 | |
| 21 | export const cloneRepo = ( |
| 22 | spawner: typeof execa, |
| 23 | suppressOutput = false |
| 24 | ) => async ( |
| 25 | repoInfo: { |
| 26 | readonly branch: string; |
| 27 | readonly repo: string; |
| 28 | }, |
| 29 | workingDirectory: string, |
| 30 | dir: string |
| 31 | ) => { |
| 32 | const projectDir = join(workingDirectory, dir); |
| 33 | const gitHistoryDir = join(projectDir, '.git'); |
| 34 | const args = |
| 35 | repoInfo.branch === '.' |
| 36 | ? ['clone', '--depth=1', repoInfo.repo, dir] |
| 37 | : [ |
| 38 | 'clone', |
| 39 | '--depth=1', |
| 40 | `--branch=${repoInfo.branch}`, |
| 41 | repoInfo.repo, |
| 42 | dir, |
| 43 | ]; |
| 44 | try { |
| 45 | await spawner('git', args, { |
| 46 | cwd: workingDirectory, |
| 47 | stdio: suppressOutput ? 'pipe' : 'inherit', |
| 48 | }); |
| 49 | } catch (err) { |
| 50 | if (err.exitCodeName === 'ENOENT') { |
| 51 | // eslint-disable-next-line functional/no-throw-statement |
| 52 | throw new Error(` |
| 53 | Git is not installed on your PATH. Please install Git and try again. |
| 54 | |
| 55 | For more information, visit: https://git-scm.com/book/en/v2/Getting-Started-Installing-Git |
| 56 | `); |
| 57 | } else { |
| 58 | // eslint-disable-next-line functional/no-throw-statement |
| 59 | throw new Error(`Git clone failed.`); |
| 60 | } |
| 61 | } |
| 62 | try { |
| 63 | const revParseResult = await spawner('git', ['rev-parse', 'HEAD'], { |
| 64 | cwd: projectDir, |
| 65 | encoding: 'utf8', |
| 66 | stdio: ['pipe', 'pipe', 'inherit'], |
| 67 | }); |
| 68 | const commitHash = revParseResult.stdout; |
| 69 | return { commitHash, gitHistoryDir }; |
| 70 | } catch (err) { |
| 71 | // eslint-disable-next-line functional/no-throw-statement |
| 72 | throw new Error(`Git rev-parse failed.`); |
| 73 | } |
| 74 | }; |
| 75 | |
| 76 | export const getGithubUsername = ( |
| 77 | // eslint-disable-next-line @typescript-eslint/no-explicit-any |
no outgoing calls