mirror of
https://github.com/pacnpal/Pac-cogs.git
synced 2025-12-20 02:41:06 -05:00
Update claude-review.yml
This commit is contained in:
49
.github/workflows/claude-review.yml
vendored
49
.github/workflows/claude-review.yml
vendored
@@ -102,8 +102,11 @@ jobs:
|
||||
echo "Found $DIFF_SIZE bytes of relevant changes"
|
||||
echo "diff_size=$DIFF_SIZE" >> $GITHUB_OUTPUT
|
||||
|
||||
# Create prompt text in a file for better handling
|
||||
cat > prompt.txt << 'EOL'
|
||||
# Prepare content for API request
|
||||
DIFF_CONTENT=$(cat filtered_diff.txt)
|
||||
|
||||
# Create prompt in a way that preserves formatting
|
||||
PROMPT=$(cat << 'EOL'
|
||||
You are performing a code review. Please analyze this code diff and provide a thorough review that covers:
|
||||
|
||||
1. Potential conflicts with existing codebase
|
||||
@@ -126,20 +129,19 @@ jobs:
|
||||
|
||||
```
|
||||
EOL
|
||||
|
||||
cat filtered_diff.txt >> prompt.txt
|
||||
echo '```' >> prompt.txt
|
||||
)
|
||||
|
||||
# Create API request
|
||||
REQUEST_JSON=$(jq -n \
|
||||
--arg content "$(cat prompt.txt)" \
|
||||
REQUEST=$(jq -n \
|
||||
--arg prompt "$PROMPT" \
|
||||
--arg diff "$DIFF_CONTENT" \
|
||||
'{
|
||||
model: "claude-3-sonnet-20240229",
|
||||
max_tokens: 4096,
|
||||
temperature: 0.7,
|
||||
messages: [{
|
||||
role: "user",
|
||||
content: $content
|
||||
content: ($prompt + "\n" + $diff + "\n```")
|
||||
}]
|
||||
}')
|
||||
|
||||
@@ -149,7 +151,7 @@ jobs:
|
||||
-H "Content-Type: application/json" \
|
||||
-H "x-api-key: $ANTHROPIC_API_KEY" \
|
||||
-H "anthropic-version: 2023-06-01" \
|
||||
-d "$REQUEST_JSON")
|
||||
-d "$REQUEST")
|
||||
|
||||
# Process the response
|
||||
if echo "$RESPONSE" | jq -e '.content[0].text' > /dev/null; then
|
||||
@@ -160,28 +162,10 @@ jobs:
|
||||
} >> $GITHUB_OUTPUT
|
||||
else
|
||||
echo "Error in Claude API response: $RESPONSE"
|
||||
echo "Request was: $REQUEST_JSON"
|
||||
echo "Request was: $REQUEST"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
- name: Process review
|
||||
if: success() && steps.analysis.outputs.diff_size != '0'
|
||||
id: process-review
|
||||
uses: actions/github-script@v7
|
||||
with:
|
||||
script: |
|
||||
const review = `${{ steps.analysis.outputs.review }}`;
|
||||
|
||||
// Process review text to properly escape code blocks
|
||||
const processedReview = review
|
||||
.replace(/```/g, '\\`\\`\\`')
|
||||
.replace(/`([^`]+)`/g, '\\`$1\\`')
|
||||
.replace(/\${/g, '\\${');
|
||||
|
||||
return {
|
||||
text: processedReview
|
||||
};
|
||||
|
||||
- name: Post review comment
|
||||
if: success() && steps.analysis.outputs.diff_size != '0'
|
||||
uses: actions/github-script@v7
|
||||
@@ -190,11 +174,16 @@ jobs:
|
||||
script: |
|
||||
const { owner, repo } = context.repo;
|
||||
const prNumber = ${{ steps.pr-number.outputs.number }};
|
||||
const review = ${{ steps.process-review.outputs.result }}.text;
|
||||
|
||||
// Prepare review text
|
||||
const reviewText = `${{ steps.analysis.outputs.review }}`
|
||||
.replace(/(?<=[\s\n])`([^`]+)`(?=[\s\n])/g, '\\`$1\\`')
|
||||
.replace(/```/g, '\\`\\`\\`')
|
||||
.replace(/\${/g, '\\${');
|
||||
|
||||
await github.rest.issues.createComment({
|
||||
owner,
|
||||
repo,
|
||||
issue_number: prNumber,
|
||||
body: "# Claude Code Review\n\n" + review
|
||||
body: "# Claude Code Review\n\n" + reviewText
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user