(raw: Record<string, unknown>)
| 284 | ].join(","); |
| 285 | |
| 286 | function parseGhPRContext(raw: Record<string, unknown>): PRContext { |
| 287 | const arr = (v: unknown): unknown[] => (Array.isArray(v) ? v : []); |
| 288 | const str = (v: unknown): string => (typeof v === "string" ? v : ""); |
| 289 | const login = (v: unknown): string => |
| 290 | typeof v === "object" && v !== null && "login" in v |
| 291 | ? String((v as { login: unknown }).login || "") |
| 292 | : ""; |
| 293 | |
| 294 | return { |
| 295 | body: str(raw.body), |
| 296 | state: str(raw.state), |
| 297 | isDraft: raw.isDraft === true, |
| 298 | labels: arr(raw.labels).map((l: any) => ({ |
| 299 | name: str(l?.name), |
| 300 | color: str(l?.color), |
| 301 | })), |
| 302 | reviewDecision: str(raw.reviewDecision), |
| 303 | mergeable: str(raw.mergeable), |
| 304 | mergeStateStatus: str(raw.mergeStateStatus), |
| 305 | comments: arr(raw.comments).map((c: any) => ({ |
| 306 | id: str(c?.id), |
| 307 | author: login(c?.author), |
| 308 | body: str(c?.body), |
| 309 | createdAt: str(c?.createdAt), |
| 310 | url: str(c?.url), |
| 311 | })), |
| 312 | reviews: arr(raw.reviews).map((r: any) => ({ |
| 313 | id: str(r?.id), |
| 314 | author: login(r?.author), |
| 315 | state: str(r?.state), |
| 316 | body: str(r?.body), |
| 317 | submittedAt: str(r?.submittedAt), |
| 318 | ...(r?.url ? { url: str(r.url) } : {}), |
| 319 | })), |
| 320 | reviewThreads: [], // populated via GraphQL after initial fetch |
| 321 | checks: arr(raw.statusCheckRollup).map((c: any) => ({ |
| 322 | name: str(c?.name), |
| 323 | status: str(c?.status), |
| 324 | conclusion: typeof c?.conclusion === "string" ? c.conclusion : null, |
| 325 | workflowName: str(c?.workflowName), |
| 326 | detailsUrl: str(c?.detailsUrl), |
| 327 | })), |
| 328 | linkedIssues: arr(raw.closingIssuesReferences).map((i: any) => ({ |
| 329 | number: typeof i?.number === "number" ? i.number : 0, |
| 330 | url: str(i?.url), |
| 331 | repo: i?.repository |
| 332 | ? `${login(i.repository.owner)}/${str(i.repository.name)}` |
| 333 | : "", |
| 334 | })), |
| 335 | }; |
| 336 | } |
| 337 | |
| 338 | export async function fetchGhPRContext( |
| 339 | runtime: PRRuntime, |
no test coverage detected