(exitCode: number, stdout: string, stderr: string)
| 116 | } |
| 117 | |
| 118 | function resultFromExitCode(exitCode: number, stdout: string, stderr: string): HookResult { |
| 119 | if (exitCode === 2) { |
| 120 | const message = stderr.trim(); |
| 121 | return { |
| 122 | action: 'block', |
| 123 | message, |
| 124 | reason: message, |
| 125 | stdout, |
| 126 | stderr, |
| 127 | exitCode, |
| 128 | }; |
| 129 | } |
| 130 | |
| 131 | const structured = exitCode === 0 ? structuredOutput(stdout) : undefined; |
| 132 | if (structured?.action === 'block') { |
| 133 | return { |
| 134 | action: 'block', |
| 135 | message: structured.message ?? structured.reason, |
| 136 | reason: structured.reason, |
| 137 | stdout, |
| 138 | stderr, |
| 139 | exitCode, |
| 140 | structuredOutput: structured.structuredOutput, |
| 141 | }; |
| 142 | } |
| 143 | |
| 144 | return allowResult({ |
| 145 | message: structured?.message, |
| 146 | stdout, |
| 147 | stderr, |
| 148 | exitCode, |
| 149 | structuredOutput: structured?.structuredOutput, |
| 150 | }); |
| 151 | } |
| 152 | |
| 153 | function structuredOutput( |
| 154 | stdout: string, |
no test coverage detected