( runtime: PRRuntime, ref: GhPRRef, sha: string, filePath: string, )
| 484 | // --- File Content --- |
| 485 | |
| 486 | export async function fetchGhPRFileContent( |
| 487 | runtime: PRRuntime, |
| 488 | ref: GhPRRef, |
| 489 | sha: string, |
| 490 | filePath: string, |
| 491 | ): Promise<string | null> { |
| 492 | const result = await runtime.runCommand("gh", hostnameArgs(ref.host, [ |
| 493 | "api", |
| 494 | `repos/${ref.owner}/${ref.repo}/contents/${encodeApiFilePath(filePath)}?ref=${sha}`, |
| 495 | "--jq", ".content", |
| 496 | ])); |
| 497 | |
| 498 | if (result.exitCode !== 0) return null; |
| 499 | |
| 500 | const base64Content = result.stdout.trim(); |
| 501 | if (!base64Content) return null; |
| 502 | |
| 503 | // GitHub returns base64-encoded content with newlines |
| 504 | const cleaned = base64Content.replace(/\n/g, ""); |
| 505 | try { |
| 506 | return Buffer.from(cleaned, "base64").toString("utf-8"); |
| 507 | } catch { |
| 508 | return null; |
| 509 | } |
| 510 | } |
| 511 | |
| 512 | // --- Viewed Files --- |
| 513 |
no test coverage detected