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

Function fetchGhPRContext

packages/shared/pr-github.ts:338–381  ·  view source on GitHub ↗
(
  runtime: PRRuntime,
  ref: GhPRRef,
)

Source from the content-addressed store, hash-verified

336}
337
338export async function fetchGhPRContext(
339 runtime: PRRuntime,
340 ref: GhPRRef,
341): Promise<PRContext> {
342 const repo = repoFlag(ref);
343
344 const result = await runtime.runCommand("gh", [
345 "pr", "view", String(ref.number),
346 "--repo", repo,
347 "--json", GH_CONTEXT_FIELDS,
348 ]);
349
350 if (result.exitCode !== 0) {
351 throw new Error(
352 `Failed to fetch PR context: ${result.stderr.trim() || `exit code ${result.exitCode}`}`,
353 );
354 }
355
356 const raw = JSON.parse(result.stdout) as Record<string, unknown>;
357 const context = parseGhPRContext(raw);
358
359 // Fetch inline review threads + bot author logins via GraphQL (the only place
360 // GitHub exposes whether an author is a Bot vs a User — `gh pr view --json`
361 // gives the login only). Non-blocking failure: degrade to no threads / no bot
362 // tags rather than failing the whole context.
363 try {
364 const { threads, botLogins, avatarByLogin } = await fetchGhThreadsAndBots(runtime, ref);
365 context.reviewThreads = threads;
366 for (const c of context.comments) {
367 if (botLogins.has(c.author)) c.isBot = true;
368 const a = avatarByLogin.get(c.author);
369 if (a) c.avatarUrl = a;
370 }
371 for (const r of context.reviews) {
372 if (botLogins.has(r.author)) r.isBot = true;
373 const a = avatarByLogin.get(r.author);
374 if (a) r.avatarUrl = a;
375 }
376 } catch {
377 context.reviewThreads = [];
378 }
379
380 return context;
381}
382
383// --- Review Threads + bot detection (GraphQL) ---
384

Callers 1

fetchPRContextFunction · 0.90

Calls 6

repoFlagFunction · 0.85
parseGhPRContextFunction · 0.85
fetchGhThreadsAndBotsFunction · 0.85
parseMethod · 0.80
hasMethod · 0.80
getMethod · 0.65

Tested by

no test coverage detected