mirror of
https://github.com/anthropics/claude-code-action.git
synced 2026-08-03 09:48:31 +08:00
docs: fix execution file parsing example (#1297)
This commit is contained in:
parent
36617bd48b
commit
eba921ff6f
@ -148,9 +148,11 @@ Do not set `anthropic_api_key` or `claude_code_oauth_token` alongside the federa
|
||||
## Outputs
|
||||
|
||||
| Output | Description |
|
||||
| ---------------- | ---------------------------------------------------------- |
|
||||
| ------------------- | ------------------------------------------------------------------------------------------------- |
|
||||
| `conclusion` | Execution status of Claude Code ('success' or 'failure') |
|
||||
| `execution_file` | Path to the JSON file containing Claude Code execution log |
|
||||
| `structured_output` | JSON string containing structured output fields when `--json-schema` is provided in `claude_args` |
|
||||
| `session_id` | The Claude Code session ID that can be used with `--resume` to continue this conversation |
|
||||
|
||||
## Environment Variables
|
||||
|
||||
@ -395,18 +397,39 @@ jobs:
|
||||
const executionFile = '${{ steps.code-review.outputs.execution_file }}';
|
||||
const executionLog = JSON.parse(fs.readFileSync(executionFile, 'utf8'));
|
||||
|
||||
// Extract the review content from the execution log
|
||||
// The execution log contains the full conversation including Claude's responses
|
||||
// Extract the review content from the execution log.
|
||||
// The SDK writes top-level events with `type`; assistant text is nested
|
||||
// under `message.content`.
|
||||
let review = '';
|
||||
|
||||
// Find the last assistant message which should contain the review
|
||||
// Prefer the final result event when it is available.
|
||||
for (let i = executionLog.length - 1; i >= 0; i--) {
|
||||
if (executionLog[i].role === 'assistant') {
|
||||
review = executionLog[i].content;
|
||||
const entry = executionLog[i];
|
||||
if (entry?.type === 'result' && typeof entry.result === 'string') {
|
||||
review = entry.result;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Fallback to the last assistant text block if no result event was written.
|
||||
if (!review) {
|
||||
for (let i = executionLog.length - 1; i >= 0; i--) {
|
||||
const entry = executionLog[i];
|
||||
if (entry?.type !== 'assistant' || !Array.isArray(entry.message?.content)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
review = entry.message.content
|
||||
.filter((block) => block?.type === 'text' && typeof block.text === 'string')
|
||||
.map((block) => block.text)
|
||||
.join('\n');
|
||||
|
||||
if (review) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (review) {
|
||||
github.rest.issues.createComment({
|
||||
issue_number: context.issue.number,
|
||||
@ -417,6 +440,10 @@ jobs:
|
||||
}
|
||||
```
|
||||
|
||||
For typed automation output, prefer passing `--json-schema` in `claude_args`
|
||||
and reading `steps.<id>.outputs.structured_output` instead of parsing the full
|
||||
execution log.
|
||||
|
||||
Check out additional examples in [`./examples`](./examples).
|
||||
|
||||
## Using Cloud Providers
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user