* Accept all pending suggestions for a PR.
(prUrl: string)
| 205 | * Accept all pending suggestions for a PR. |
| 206 | */ |
| 207 | async function acceptChecks(prUrl: string): Promise<void> { |
| 208 | const response = await get<ChecksStatusResponse>( |
| 209 | `api/checks/status?pullRequestUrl=${encodeURIComponent(prUrl)}`, |
| 210 | ); |
| 211 | const { checks } = response.data; |
| 212 | |
| 213 | const pending = checks.filter( |
| 214 | (c) => c.suggestionStatus === "pending" && c.commitMessage, |
| 215 | ); |
| 216 | |
| 217 | if (pending.length === 0) { |
| 218 | console.log(chalk.dim("No pending suggestions to accept.")); |
| 219 | return; |
| 220 | } |
| 221 | |
| 222 | console.log( |
| 223 | chalk.bold(`Accepting ${pending.length} pending suggestion(s)...\n`), |
| 224 | ); |
| 225 | |
| 226 | for (const check of pending) { |
| 227 | try { |
| 228 | await post(`agents/${check.sessionId}/accept`); |
| 229 | console.log(chalk.green(`\u2714 Accepted: ${check.name}`)); |
| 230 | } catch (err) { |
| 231 | const msg = err instanceof Error ? err.message : String(err); |
| 232 | console.error( |
| 233 | chalk.red(`\u2716 Failed to accept ${check.name}: ${msg}`), |
| 234 | ); |
| 235 | } |
| 236 | } |
| 237 | } |
| 238 | |
| 239 | /** |
| 240 | * Reject all pending suggestions for a PR. |