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 "Found $DIFF_SIZE bytes of relevant changes"
|
||||||
echo "diff_size=$DIFF_SIZE" >> $GITHUB_OUTPUT
|
echo "diff_size=$DIFF_SIZE" >> $GITHUB_OUTPUT
|
||||||
|
|
||||||
# Create prompt text in a file for better handling
|
# Prepare content for API request
|
||||||
cat > prompt.txt << 'EOL'
|
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:
|
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
|
||||||
@@ -126,20 +129,19 @@ jobs:
|
|||||||
|
|
||||||
```
|
```
|
||||||
EOL
|
EOL
|
||||||
|
)
|
||||||
|
|
||||||
cat filtered_diff.txt >> prompt.txt
|
|
||||||
echo '```' >> prompt.txt
|
|
||||||
|
|
||||||
# Create API request
|
# Create API request
|
||||||
REQUEST_JSON=$(jq -n \
|
REQUEST=$(jq -n \
|
||||||
--arg content "$(cat prompt.txt)" \
|
--arg prompt "$PROMPT" \
|
||||||
|
--arg diff "$DIFF_CONTENT" \
|
||||||
'{
|
'{
|
||||||
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: $content
|
content: ($prompt + "\n" + $diff + "\n```")
|
||||||
}]
|
}]
|
||||||
}')
|
}')
|
||||||
|
|
||||||
@@ -149,7 +151,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_JSON")
|
-d "$REQUEST")
|
||||||
|
|
||||||
# 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
|
||||||
@@ -160,28 +162,10 @@ 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_JSON"
|
echo "Request was: $REQUEST"
|
||||||
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
|
||||||
@@ -190,11 +174,16 @@ jobs:
|
|||||||
script: |
|
script: |
|
||||||
const { owner, repo } = context.repo;
|
const { owner, repo } = context.repo;
|
||||||
const prNumber = ${{ steps.pr-number.outputs.number }};
|
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({
|
await github.rest.issues.createComment({
|
||||||
owner,
|
owner,
|
||||||
repo,
|
repo,
|
||||||
issue_number: prNumber,
|
issue_number: prNumber,
|
||||||
body: "# Claude Code Review\n\n" + review
|
body: "# Claude Code Review\n\n" + reviewText
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user