* Helper to convert ChildProcess to Promise with stdout/stderr
( proc: ReturnType<CodebuffSpawn>, )
| 233 | * Helper to convert ChildProcess to Promise with stdout/stderr |
| 234 | */ |
| 235 | function childProcessToPromise( |
| 236 | proc: ReturnType<CodebuffSpawn>, |
| 237 | ): Promise<{ stdout: string; stderr: string }> { |
| 238 | return new Promise((resolve, reject) => { |
| 239 | let stdout = '' |
| 240 | let stderr = '' |
| 241 | |
| 242 | proc.stdout?.on('data', (data: Buffer) => { |
| 243 | stdout += data.toString() |
| 244 | }) |
| 245 | |
| 246 | proc.stderr?.on('data', (data: Buffer) => { |
| 247 | stderr += data.toString() |
| 248 | }) |
| 249 | |
| 250 | proc.on('close', (code: number | null) => { |
| 251 | if (code === 0) { |
| 252 | resolve({ stdout, stderr }) |
| 253 | } else { |
| 254 | reject(new Error(`Command exited with code ${code}`)) |
| 255 | } |
| 256 | }) |
| 257 | |
| 258 | proc.on('error', reject) |
| 259 | }) |
| 260 | } |
| 261 | |
| 262 | /** |
| 263 | * Retrieves git changes for the project using the provided spawn function |
no test coverage detected