* Retrieve the file content for a specified file, properly handling the file not existing in the * repo and returning a 404.
(github: Octokit, repo: string, path: string)
| 43 | * repo and returning a 404. |
| 44 | */ |
| 45 | async function getFile(github: Octokit, repo: string, path: string): Promise<File | null> { |
| 46 | core.info(`Retrieving "${path}" from ${repo} repo`); |
| 47 | return github.rest.repos.getContent({owner: context.repo.owner, repo, path}).then( |
| 48 | (response) => { |
| 49 | if ((response.data as {content?: string}).content !== undefined) { |
| 50 | return response.data as File; |
| 51 | } |
| 52 | return null; |
| 53 | }, |
| 54 | (reason: RequestError) => { |
| 55 | if (reason.status === 404) { |
| 56 | core.warning(`"${path}" does not exist in "${repo}" repo`); |
| 57 | return null; |
| 58 | } |
| 59 | throw reason; |
| 60 | }, |
| 61 | ); |
| 62 | } |
| 63 | |
| 64 | /** |
| 65 | * Update the target repo to ensure the provided golden file contents are used for the files |