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:
65
.github/workflows/claude-review.yml
vendored
65
.github/workflows/claude-review.yml
vendored
@@ -73,60 +73,50 @@ jobs:
|
||||
|
||||
echo "Comparing $BASE_SHA..$HEAD_SHA"
|
||||
|
||||
# Get the diff
|
||||
DIFF_CONTENT=$(git diff -U10 "$BASE_SHA" "$HEAD_SHA" | \
|
||||
grep -v -E '^diff --git .*(package-lock\.json|yarn\.lock|\.md|\.json)' | \
|
||||
grep -E '\.(js|ts|py|cpp|h|java|cs)$')
|
||||
# Generate the full diff
|
||||
git diff -U10 "$BASE_SHA" "$HEAD_SHA" > full_diff.txt
|
||||
|
||||
if [ -z "$DIFF_CONTENT" ]; then
|
||||
# Use awk to properly capture full context of relevant files
|
||||
awk '
|
||||
BEGIN { found=0; buffer="" }
|
||||
/^diff --git/ {
|
||||
if (found) { print buffer }
|
||||
found=0; buffer=""
|
||||
if ($0 ~ /\.(js|ts|py|cpp|h|java|cs)$/ && $0 !~ /(package-lock\.json|yarn\.lock|\.md|\.json)/) {
|
||||
found=1
|
||||
}
|
||||
}
|
||||
{ if (found) buffer = buffer $0 "\n" }
|
||||
END { if (found) print buffer }
|
||||
' full_diff.txt > filtered_diff.txt
|
||||
|
||||
# Check if we have any relevant changes
|
||||
if [ ! -s filtered_diff.txt ]; then
|
||||
echo "No relevant changes found"
|
||||
echo "diff_size=0" >> $GITHUB_OUTPUT
|
||||
exit 0
|
||||
fi
|
||||
|
||||
DIFF_SIZE=${#DIFF_CONTENT}
|
||||
# Get file size and content
|
||||
DIFF_SIZE=$(wc -c < filtered_diff.txt)
|
||||
echo "Found $DIFF_SIZE bytes of relevant changes"
|
||||
echo "diff_size=$DIFF_SIZE" >> $GITHUB_OUTPUT
|
||||
|
||||
# Create prompt
|
||||
PROMPT="You are performing a code review. Please analyze this code diff and provide a thorough review that covers:
|
||||
|
||||
1. Potential conflicts with existing codebase
|
||||
2. Code correctness and potential bugs
|
||||
3. Security vulnerabilities or risks
|
||||
4. Performance implications
|
||||
5. Maintainability and readability issues
|
||||
6. Adherence to best practices and coding standards
|
||||
7. Suggestions for improvements
|
||||
|
||||
For each issue found:
|
||||
- Explain the problem clearly
|
||||
- Rate the severity (Critical/High/Medium/Low)
|
||||
- Provide specific recommendations for fixes
|
||||
- Include code examples where helpful
|
||||
|
||||
If no issues are found in a particular area, explicitly state that.
|
||||
|
||||
Here is the code diff to review:
|
||||
|
||||
\`\`\`
|
||||
$DIFF_CONTENT
|
||||
\`\`\`"
|
||||
|
||||
# Create API request
|
||||
# Create the API request
|
||||
DIFF_CONTENT=$(cat filtered_diff.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": $prompt
|
||||
"content": "You are performing a code review. Please analyze this code diff and provide a thorough review that covers:\n\n1. Potential conflicts with existing codebase\n2. Code correctness and potential bugs\n3. Security vulnerabilities or risks\n4. Performance implications\n5. Maintainability and readability issues\n6. Adherence to best practices and coding standards\n7. Suggestions for improvements\n\nFor each issue found:\n- Explain the problem clearly\n- Rate the severity (Critical/High/Medium/Low)\n- Provide specific recommendations for fixes\n- Include code examples where helpful\n\nIf no issues are found in a particular area, explicitly state that.\n\nHere is the code diff to review:\n\n```\n" + $diff + "\n```"
|
||||
}]
|
||||
}')
|
||||
|
||||
# Call API
|
||||
# Call the API
|
||||
echo "Sending request to Claude API..."
|
||||
RESPONSE=$(curl -s https://api.anthropic.com/v1/messages \
|
||||
-H "Content-Type: application/json" \
|
||||
@@ -134,7 +124,7 @@ jobs:
|
||||
-H "anthropic-version: 2023-06-01" \
|
||||
-d "$REQUEST")
|
||||
|
||||
# Process response
|
||||
# Process the response
|
||||
if echo "$RESPONSE" | jq -e '.content[0].text' > /dev/null; then
|
||||
{
|
||||
echo 'review<<EOF'
|
||||
@@ -143,6 +133,7 @@ jobs:
|
||||
} >> $GITHUB_OUTPUT
|
||||
else
|
||||
echo "Error in Claude API response: $RESPONSE"
|
||||
echo "Request was: $REQUEST"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
@@ -153,8 +144,8 @@ jobs:
|
||||
github-token: ${{ secrets.GITHUB_TOKEN }}
|
||||
script: |
|
||||
const { owner, repo } = context.repo;
|
||||
const prNumber = ${{ steps.pr-number.outputs.number }};
|
||||
const review = `${{ steps.analysis.outputs.review }}`;
|
||||
const prNumber = ${{ steps.pr-number.outputs.number }};
|
||||
|
||||
await github.rest.issues.createComment({
|
||||
owner,
|
||||
|
||||
Reference in New Issue
Block a user