(rootDir: string)
| 343 | * normal PR detection used by `ci check`. |
| 344 | */ |
| 345 | export function resolveTargetPrNumber(rootDir: string): string | null { |
| 346 | if (process.env.GITHUB_EVENT_NAME === 'workflow_run') { |
| 347 | const event = readGitHubEventPayload(); |
| 348 | const headSha = event?.workflow_run?.head_sha; |
| 349 | const repo = process.env.GITHUB_REPOSITORY; |
| 350 | // Sanitize both before they reach the gh api path: a 40-hex SHA and an owner/repo slug. |
| 351 | if (headSha && /^[0-9a-f]{40}$/i.test(headSha) && repo && /^[\w.-]+\/[\w.-]+$/.test(repo)) { |
| 352 | const out = tryRunArgs( |
| 353 | ['gh', 'api', `repos/${repo}/commits/${headSha}/pulls`, '--jq', '.[] | select(.state == "open") | .number'], |
| 354 | { cwd: rootDir }, |
| 355 | ); |
| 356 | return ( |
| 357 | out |
| 358 | ?.split('\n') |
| 359 | .map((l) => l.trim()) |
| 360 | .find((l) => /^\d+$/.test(l)) ?? null |
| 361 | ); |
| 362 | } |
| 363 | return null; |
| 364 | } |
| 365 | return detectPrNumber(); |
| 366 | } |
| 367 | |
| 368 | // ---- ci plan ---- |
| 369 |
no test coverage detected
searching dependent graphs…