import { components } from "@octokit/openapi-types" ; import { ProbotOctokit } from "probot" ; import { DevError } from "../logging/dev-error" ; type GetRepoContentResponseDataFile = components [ "schemas" ] [ "content-file" ] ; /** Loads the content of the given file in the given branch from GitHub. */ export async function loadFile ( args ) { const result = await args . octokit . repos . getContent ( { owner : args . org , path : args . filePath , ref : args . branch , repo : args . repo , } ) ; if ( result . data instanceof Array ) { throw new DevError ( "loading the content of a file from GitHub" , new Error ( ) , { filePath : args . filePath , message : "Received unexpected array while loading a single file from GitHub, expected single entry" , } ) ; } const fileResponse = result . data as GetRepoContentResponseDataFile ; return Buffer . from ( fileResponse . content || "" , "base64" ) . toString ( ) ; }