Skip to content

Commit ece407c

Browse files
Fix critical JSON formatting bug in ampcode workflow (#1955)
Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Co-authored-by: Adam <[email protected]>
1 parent 9f7803f commit ece407c

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

.github/workflows/ampcode-pr-review.yml

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -92,16 +92,19 @@ jobs:
9292
# Read the review output
9393
REVIEW_CONTENT=$(cat ampcode_review.txt)
9494
95-
# Sanitize the review content to prevent injection attacks
96-
SANITIZED_CONTENT=$(echo "$REVIEW_CONTENT" | sed 's/"/\\"/g' | sed 's/`/\\`/g' | sed 's/\$/\\$/g' | tr '\n' ' ')
95+
# Create a comprehensive PR review comment using proper JSON escaping
96+
# Use jq to properly escape the review content for JSON
97+
ESCAPED_CONTENT=$(echo "$REVIEW_CONTENT" | jq -Rs .)
9798
98-
# Create a comprehensive PR review comment with sanitized content
99-
cat > review_comment.json << EOF
100-
{
101-
"body": "## 🤖 Automated Code Review by Ampcode\n\n**Review Summary:**\n\nI've analyzed the changes in this PR using AI-powered code review. Here are my findings:\n\n### 📋 Review Results\n\n\`\`\`\n${SANITIZED_CONTENT}\n\`\`\`\n\n### 🔍 Key Areas Reviewed\n- Code quality and best practices\n- Potential bugs and security issues\n- Performance considerations\n- Maintainability and readability\n\n### 📝 Notes\n- This is an automated review generated by Ampcode AI\n- Please review the suggestions and apply them as appropriate\n- For questions about specific recommendations, feel free to ask!\n\n---\n*Generated by [Ampcode](https://ampcode.com) • [View Workflow](https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }})*",
102-
"event": "COMMENT"
103-
}
104-
EOF
99+
# Create the JSON payload with proper escaping
100+
jq -n \
101+
--arg content "$REVIEW_CONTENT" \
102+
--arg run_id "${{ github.run_id }}" \
103+
--arg repo "${{ github.repository }}" \
104+
'{
105+
"body": ("## 🤖 Automated Code Review by Ampcode\n\n**Review Summary:**\n\nI'\''ve analyzed the changes in this PR using AI-powered code review. Here are my findings:\n\n### 📋 Review Results\n\n```\n" + $content + "\n```\n\n### 🔍 Key Areas Reviewed\n- Code quality and best practices\n- Potential bugs and security issues\n- Performance considerations\n- Maintainability and readability\n\n### 📝 Notes\n- This is an automated review generated by Ampcode AI\n- Please review the suggestions and apply them as appropriate\n- For questions about specific recommendations, feel free to ask!\n\n---\n*Generated by [Ampcode](https://ampcode.com) • [View Workflow](https://github.com/" + $repo + "/actions/runs/" + $run_id + ")*"),
106+
"event": "COMMENT"
107+
}' > review_comment.json
105108
106109
# Post the review comment
107110
curl -X POST \

0 commit comments

Comments
 (0)