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:
58
.github/workflows/claude-review.yml
vendored
58
.github/workflows/claude-review.yml
vendored
@@ -73,30 +73,23 @@ jobs:
|
|||||||
|
|
||||||
echo "Comparing $BASE_SHA..$HEAD_SHA"
|
echo "Comparing $BASE_SHA..$HEAD_SHA"
|
||||||
|
|
||||||
# Get the full diff with context
|
# Get the diff
|
||||||
git diff -U10 "$BASE_SHA" "$HEAD_SHA" > diff_full.txt
|
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)$')
|
||||||
|
|
||||||
# Filter for relevant files
|
if [ -z "$DIFF_CONTENT" ]; then
|
||||||
cat diff_full.txt | \
|
|
||||||
awk '/^diff --git/{p=0} /\.(js|ts|py|cpp|h|java|cs)$/{p=1} p' | \
|
|
||||||
grep -v -E '^diff --git .*(package-lock\.json|yarn\.lock|\.md|\.json)' > diff_filtered.txt
|
|
||||||
|
|
||||||
if [ ! -s diff_filtered.txt ]; then
|
|
||||||
echo "No relevant changes found"
|
echo "No relevant changes found"
|
||||||
echo "diff_size=0" >> $GITHUB_OUTPUT
|
echo "diff_size=0" >> $GITHUB_OUTPUT
|
||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
DIFF_SIZE=$(wc -c < diff_filtered.txt)
|
DIFF_SIZE=${#DIFF_CONTENT}
|
||||||
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
|
||||||
|
|
||||||
# Prepare the diff content
|
# Create prompt
|
||||||
DIFF_CONTENT=$(cat diff_filtered.txt)
|
PROMPT="You are performing a code review. Please analyze this code diff and provide a thorough review that covers:
|
||||||
|
|
||||||
# Create the JSON payload
|
|
||||||
read -r -d '' PROMPT << EOM
|
|
||||||
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
|
||||||
@@ -117,40 +110,39 @@ jobs:
|
|||||||
Here is the code diff to review:
|
Here is the code diff to review:
|
||||||
|
|
||||||
\`\`\`
|
\`\`\`
|
||||||
${DIFF_CONTENT}
|
$DIFF_CONTENT
|
||||||
\`\`\`
|
\`\`\`"
|
||||||
EOM
|
|
||||||
|
|
||||||
# Create API request JSON
|
# Create API request
|
||||||
REQUEST_JSON=$(jq -n \
|
REQUEST=$(jq -n \
|
||||||
--arg prompt "$PROMPT" \
|
--arg prompt "$PROMPT" \
|
||||||
'{
|
'{
|
||||||
"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": $prompt
|
}]
|
||||||
}
|
|
||||||
]
|
|
||||||
}')
|
}')
|
||||||
|
|
||||||
# Make API request and capture response in a file to preserve formatting
|
# Call API
|
||||||
echo "Sending request to Claude API..."
|
echo "Sending request to Claude API..."
|
||||||
RESPONSE=$(curl -s https://api.anthropic.com/v1/messages \
|
RESPONSE=$(curl -s https://api.anthropic.com/v1/messages \
|
||||||
-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 response
|
||||||
if echo "$RESPONSE" | jq -e '.content[0].text' > /dev/null; then
|
if echo "$RESPONSE" | jq -e '.content[0].text' > /dev/null; then
|
||||||
echo 'review<<EOF' >> $GITHUB_OUTPUT
|
{
|
||||||
echo "$RESPONSE" | jq -r '.content[0].text' >> $GITHUB_OUTPUT
|
echo 'review<<EOF'
|
||||||
echo 'EOF' >> $GITHUB_OUTPUT
|
echo "$RESPONSE" | jq -r '.content[0].text'
|
||||||
|
echo 'EOF'
|
||||||
|
} >> $GITHUB_OUTPUT
|
||||||
else
|
else
|
||||||
echo "Error in Claude API response: $RESPONSE"
|
echo "Error in Claude API response: $RESPONSE"
|
||||||
echo "Request was: $REQUEST_JSON"
|
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@@ -161,8 +153,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.analysis.outputs.review }}`;
|
||||||
|
|
||||||
await github.rest.issues.createComment({
|
await github.rest.issues.createComment({
|
||||||
owner,
|
owner,
|
||||||
|
|||||||
Reference in New Issue
Block a user