( token: string, owner: string, repo: string, pullNumber: number, maxAttempts = 15, pollInterval = 1000 )
| 486 | * Wait for a PR to become mergeable by polling its status. |
| 487 | */ |
| 488 | export async function waitForMergeable( |
| 489 | token: string, |
| 490 | owner: string, |
| 491 | repo: string, |
| 492 | pullNumber: number, |
| 493 | maxAttempts = 15, |
| 494 | pollInterval = 1000 |
| 495 | ): Promise<{ mergeable: boolean; mergeable_state: string }> { |
| 496 | for (let attempt = 0; attempt < maxAttempts; attempt++) { |
| 497 | const res = await ghFetch(`/repos/${owner}/${repo}/pulls/${pullNumber}`, token); |
| 498 | if (!res.ok) { |
| 499 | if (attempt < maxAttempts - 1) { await sleep(pollInterval); continue; } |
| 500 | throw new Error(`Failed to check PR #${pullNumber} status: HTTP ${res.status}`); |
| 501 | } |
| 502 | const data = await res.json(); |
| 503 | |
| 504 | if (data.mergeable === null) { await sleep(pollInterval); continue; } |
| 505 | if (data.mergeable === true) { |
| 506 | return { mergeable: true, mergeable_state: data.mergeable_state || 'clean' }; |
| 507 | } |
| 508 | return { mergeable: false, mergeable_state: data.mergeable_state || 'unknown' }; |
| 509 | } |
| 510 | return { mergeable: false, mergeable_state: 'polling_timeout' }; |
| 511 | } |
| 512 | |
| 513 | /** |
| 514 | * Merge a PR with retries. |
no test coverage detected