Skip to content

Commit 576373f

Browse files
authored
fix(ci): unwrap double-nested JSON in claude-code-review output (#2224)
1 parent 55bbf37 commit 576373f

1 file changed

Lines changed: 19 additions & 3 deletions

File tree

.github/workflows/claude-code-review.yml

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,11 @@ jobs:
102102
Note: If the team wants a more thorough review, they can comment on the PR requesting one.
103103
104104
CRITICAL OUTPUT REQUIREMENTS:
105-
1. Return a JSON object with a single "review" field containing your full markdown review.
105+
1. Return a JSON object with a single "review" field whose VALUE
106+
is a plain markdown STRING. Do NOT put another JSON object
107+
inside the "review" string -- doing so posts raw JSON in the
108+
comment instead of rendered markdown. The `review` value must
109+
be markdown text only, not a stringified JSON envelope.
106110
2. The review markdown must start with EXACTLY these two lines:
107111
<!-- claude-code-review -->
108112
## PR Review
@@ -127,16 +131,28 @@ jobs:
127131

128132
# fromJSON() in a `with:` expression has been observed to leave the
129133
# structured_output JSON string unparsed, posting the raw envelope as
130-
# the comment body. Extract the review field via jq for reliability.
134+
# the comment body. Extract via jq.
135+
#
136+
# Defensive double-unwrap: the model has been observed to return
137+
# `{"review": "{\"review\": \"<markdown>\"}"}` -- wrapping its own JSON
138+
# output a second time so the comment body posts as raw JSON. Detect
139+
# that case (the inner string parses as an object with a `review` key)
140+
# and unwrap once more so we post markdown, not JSON. Mirrors the same
141+
# fix applied to compound-review.yml.
131142
- name: Extract review from structured output
132143
id: extract-review
133144
env:
134145
STRUCTURED_OUTPUT:
135146
${{ steps.claude-review.outputs.structured_output }}
136147
run: |
148+
REVIEW="$(printf '%s' "$STRUCTURED_OUTPUT" | jq -r '.review')"
149+
if printf '%s' "$REVIEW" | jq -e 'type == "object" and has("review")' >/dev/null 2>&1; then
150+
REVIEW="$(printf '%s' "$REVIEW" | jq -r '.review')"
151+
fi
137152
{
138153
echo 'review<<CLAUDE_REVIEW_EOF'
139-
printf '%s' "$STRUCTURED_OUTPUT" | jq -r '.review'
154+
printf '%s' "$REVIEW"
155+
echo
140156
echo 'CLAUDE_REVIEW_EOF'
141157
} >> "$GITHUB_OUTPUT"
142158

0 commit comments

Comments
 (0)