MCPcopy Create free account
hub / github.com/backnotprop/plannotator / fetchGhPRFileContent

Function fetchGhPRFileContent

packages/shared/pr-github.ts:486–510  ·  view source on GitHub ↗
(
  runtime: PRRuntime,
  ref: GhPRRef,
  sha: string,
  filePath: string,
)

Source from the content-addressed store, hash-verified

484// --- File Content ---
485
486export 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

Callers 1

fetchPRFileContentFunction · 0.90

Calls 4

encodeApiFilePathFunction · 0.90
hostnameArgsFunction · 0.85
replaceMethod · 0.80
toStringMethod · 0.80

Tested by

no test coverage detected