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:
45
.github/workflows/claude-review.yml
vendored
45
.github/workflows/claude-review.yml
vendored
@@ -102,8 +102,9 @@ jobs:
|
|||||||
echo "Found $DIFF_SIZE bytes of relevant changes"
|
echo "Found $DIFF_SIZE bytes of relevant changes"
|
||||||
echo "diff_size=$DIFF_SIZE" >> $GITHUB_OUTPUT
|
echo "diff_size=$DIFF_SIZE" >> $GITHUB_OUTPUT
|
||||||
|
|
||||||
# Create prompt text
|
# Create prompt text in a file for better handling
|
||||||
PROMPT_TEXT="You are performing a code review. Please analyze this code diff and provide a thorough review that covers:
|
cat > prompt.txt << '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
|
1. Potential conflicts with existing codebase
|
||||||
2. Code correctness and potential bugs
|
2. Code correctness and potential bugs
|
||||||
@@ -123,20 +124,22 @@ jobs:
|
|||||||
|
|
||||||
Here is the code diff to review:
|
Here is the code diff to review:
|
||||||
|
|
||||||
\`\`\`
|
```
|
||||||
$(cat filtered_diff.txt)
|
EOL
|
||||||
\`\`\`"
|
|
||||||
|
cat filtered_diff.txt >> prompt.txt
|
||||||
|
echo '```' >> prompt.txt
|
||||||
|
|
||||||
# Create API request with proper string handling
|
# Create API request
|
||||||
REQUEST=$(jq -n \
|
REQUEST_JSON=$(jq -n \
|
||||||
--arg prompt "$PROMPT_TEXT" \
|
--arg content "$(cat prompt.txt)" \
|
||||||
'{
|
'{
|
||||||
model: "claude-3-sonnet-20240229",
|
model: "claude-3-sonnet-20240229",
|
||||||
max_tokens: 4096,
|
max_tokens: 4096,
|
||||||
temperature: 0.7,
|
temperature: 0.7,
|
||||||
messages: [{
|
messages: [{
|
||||||
role: "user",
|
role: "user",
|
||||||
content: $prompt
|
content: $content
|
||||||
}]
|
}]
|
||||||
}')
|
}')
|
||||||
|
|
||||||
@@ -146,7 +149,7 @@ jobs:
|
|||||||
-H "Content-Type: application/json" \
|
-H "Content-Type: application/json" \
|
||||||
-H "x-api-key: $ANTHROPIC_API_KEY" \
|
-H "x-api-key: $ANTHROPIC_API_KEY" \
|
||||||
-H "anthropic-version: 2023-06-01" \
|
-H "anthropic-version: 2023-06-01" \
|
||||||
-d "$REQUEST")
|
-d "$REQUEST_JSON")
|
||||||
|
|
||||||
# Process the response
|
# Process the response
|
||||||
if echo "$RESPONSE" | jq -e '.content[0].text' > /dev/null; then
|
if echo "$RESPONSE" | jq -e '.content[0].text' > /dev/null; then
|
||||||
@@ -157,10 +160,28 @@ jobs:
|
|||||||
} >> $GITHUB_OUTPUT
|
} >> $GITHUB_OUTPUT
|
||||||
else
|
else
|
||||||
echo "Error in Claude API response: $RESPONSE"
|
echo "Error in Claude API response: $RESPONSE"
|
||||||
echo "Request was: $REQUEST"
|
echo "Request was: $REQUEST_JSON"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
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
|
- name: Post review comment
|
||||||
if: success() && steps.analysis.outputs.diff_size != '0'
|
if: success() && steps.analysis.outputs.diff_size != '0'
|
||||||
uses: actions/github-script@v7
|
uses: actions/github-script@v7
|
||||||
@@ -168,8 +189,8 @@ jobs:
|
|||||||
github-token: ${{ secrets.GITHUB_TOKEN }}
|
github-token: ${{ secrets.GITHUB_TOKEN }}
|
||||||
script: |
|
script: |
|
||||||
const { owner, repo } = context.repo;
|
const { owner, repo } = context.repo;
|
||||||
const review = `${{ steps.analysis.outputs.review }}`;
|
|
||||||
const prNumber = ${{ steps.pr-number.outputs.number }};
|
const prNumber = ${{ steps.pr-number.outputs.number }};
|
||||||
|
const review = ${{ steps.process-review.outputs.result }}.text;
|
||||||
|
|
||||||
await github.rest.issues.createComment({
|
await github.rest.issues.createComment({
|
||||||
owner,
|
owner,
|
||||||
|
|||||||
Reference in New Issue
Block a user