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
@ -147,10 +147,12 @@ Do not set `anthropic_api_key` or `claude_code_oauth_token` alongside the federa
|
|||||||
|
|
||||||
## Outputs
|
## Outputs
|
||||||
|
|
||||||
| Output | Description |
|
| Output | Description |
|
||||||
| ---------------- | ---------------------------------------------------------- |
|
| ------------------- | ------------------------------------------------------------------------------------------------- |
|
||||||
| `conclusion` | Execution status of Claude Code ('success' or 'failure') |
|
| `conclusion` | Execution status of Claude Code ('success' or 'failure') |
|
||||||
| `execution_file` | Path to the JSON file containing Claude Code execution log |
|
| `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
|
## Environment Variables
|
||||||
|
|
||||||
@ -395,18 +397,39 @@ jobs:
|
|||||||
const executionFile = '${{ steps.code-review.outputs.execution_file }}';
|
const executionFile = '${{ steps.code-review.outputs.execution_file }}';
|
||||||
const executionLog = JSON.parse(fs.readFileSync(executionFile, 'utf8'));
|
const executionLog = JSON.parse(fs.readFileSync(executionFile, 'utf8'));
|
||||||
|
|
||||||
// Extract the review content from the execution log
|
// Extract the review content from the execution log.
|
||||||
// The execution log contains the full conversation including Claude's responses
|
// The SDK writes top-level events with `type`; assistant text is nested
|
||||||
|
// under `message.content`.
|
||||||
let review = '';
|
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--) {
|
for (let i = executionLog.length - 1; i >= 0; i--) {
|
||||||
if (executionLog[i].role === 'assistant') {
|
const entry = executionLog[i];
|
||||||
review = executionLog[i].content;
|
if (entry?.type === 'result' && typeof entry.result === 'string') {
|
||||||
|
review = entry.result;
|
||||||
break;
|
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) {
|
if (review) {
|
||||||
github.rest.issues.createComment({
|
github.rest.issues.createComment({
|
||||||
issue_number: context.issue.number,
|
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).
|
Check out additional examples in [`./examples`](./examples).
|
||||||
|
|
||||||
## Using Cloud Providers
|
## Using Cloud Providers
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user