( runtime: PRRuntime, ref: GhPRRef, )
| 336 | } |
| 337 | |
| 338 | export 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 |
no test coverage detected