Reads a text file from a repository at a ref.
(repo: string, path: string, ref: string)
| 122 | |
| 123 | /** Reads a text file from a repository at a ref. */ |
| 124 | async fileContent(repo: string, path: string, ref: string): Promise<string> { |
| 125 | const file = await this.api<{ encoding: string; content: string }>( |
| 126 | "GET", `/repos/${repo}/contents/${path}?ref=${encodeURIComponent(ref)}`, |
| 127 | ); |
| 128 | if (file.encoding !== "base64") throw new Error(`Unexpected ${path} encoding`); |
| 129 | return Buffer.from(file.content, "base64").toString("utf8"); |
| 130 | } |
| 131 | } |