* Get raw file content from a repository
(owner: string, repo: string, path: string, ref?: string)
| 142 | * Get raw file content from a repository |
| 143 | */ |
| 144 | async getFileContent(owner: string, repo: string, path: string, ref?: string): Promise<string> { |
| 145 | try { |
| 146 | const { data } = await this.octokit.repos.getContent({ |
| 147 | owner, |
| 148 | repo, |
| 149 | path, |
| 150 | ref, |
| 151 | mediaType: { |
| 152 | format: "raw", |
| 153 | }, |
| 154 | }); |
| 155 | |
| 156 | // When using raw format, data is returned as a string |
| 157 | if (typeof data === "string") { |
| 158 | return data; |
| 159 | } |
| 160 | |
| 161 | // Fallback: if data is an object with content (base64 encoded) |
| 162 | if (!Array.isArray(data) && "content" in data && data.content) { |
| 163 | return Buffer.from(data.content, "base64").toString("utf-8"); |
| 164 | } |
| 165 | |
| 166 | throw new GitHubClientError(`Unexpected response format for file content`); |
| 167 | } catch (error) { |
| 168 | throw this.handleError(error); |
| 169 | } |
| 170 | } |
| 171 | |
| 172 | /** |
| 173 | * Check if a file exists and is within size limits |
no test coverage detected