mirror of
https://github.com/pacnpal/Pac-cogs.git
synced 2025-12-20 10:51:05 -05:00
Update claude-review.yml
This commit is contained in:
56
.github/workflows/claude-review.yml
vendored
56
.github/workflows/claude-review.yml
vendored
@@ -37,16 +37,23 @@ jobs:
|
|||||||
uses: actions/github-script@v7
|
uses: actions/github-script@v7
|
||||||
with:
|
with:
|
||||||
script: |
|
script: |
|
||||||
|
try {
|
||||||
|
const { owner, repo } = context.repo;
|
||||||
|
console.log(`Getting PR #${{ inputs.pr_number }} from ${owner}/${repo}`);
|
||||||
|
|
||||||
const pr = await github.rest.pulls.get({
|
const pr = await github.rest.pulls.get({
|
||||||
owner: context.repo.owner,
|
owner: owner,
|
||||||
repo: context.repo.name,
|
repo: repo,
|
||||||
pull_number: ${{ inputs.pr_number }}
|
pull_number: parseInt(${{ inputs.pr_number }})
|
||||||
});
|
});
|
||||||
console.log(`Base SHA: ${pr.data.base.sha}`);
|
|
||||||
console.log(`Head SHA: ${pr.data.head.sha}`);
|
|
||||||
return {
|
return {
|
||||||
base_sha: pr.data.base.sha,
|
base_sha: pr.data.base.sha,
|
||||||
head_sha: pr.data.head.sha
|
head_sha: pr.data.head.sha
|
||||||
|
};
|
||||||
|
} catch (error) {
|
||||||
|
core.setFailed(`Failed to get PR details: ${error.message}`);
|
||||||
|
throw error;
|
||||||
}
|
}
|
||||||
|
|
||||||
- name: Get changed files
|
- name: Get changed files
|
||||||
@@ -60,14 +67,21 @@ jobs:
|
|||||||
HEAD_SHA=${{ github.event.pull_request.head.sha }}
|
HEAD_SHA=${{ github.event.pull_request.head.sha }}
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
echo "Base SHA: $BASE_SHA"
|
||||||
|
echo "Head SHA: $HEAD_SHA"
|
||||||
|
|
||||||
# Get the diff and save to a file
|
# Get the diff and save to a file
|
||||||
git diff $BASE_SHA..$HEAD_SHA > changes.diff
|
git diff $BASE_SHA..$HEAD_SHA > changes.diff || echo "Failed to get diff"
|
||||||
|
|
||||||
# Create a filtered version without ignored files
|
# Create a filtered version without ignored files
|
||||||
cat changes.diff | grep -v -E '(package-lock.json|yarn.lock|node_modules|\.md$|\.json$)' | grep -E '\.(js|ts|py|cpp|h|java|cs)$' > filtered_changes.diff
|
cat changes.diff | grep -v -E '(package-lock.json|yarn.lock|node_modules|\.md$|\.json$)' | grep -E '\.(js|ts|py|cpp|h|java|cs)$' > filtered_changes.diff || true
|
||||||
|
|
||||||
# Store the size of the diff
|
# Store the size of the diff
|
||||||
echo "diff_size=$(stat -f%z filtered_changes.diff)" >> $GITHUB_OUTPUT
|
if [ -f filtered_changes.diff ]; then
|
||||||
|
echo "diff_size=$(wc -c < filtered_changes.diff)" >> $GITHUB_OUTPUT
|
||||||
|
else
|
||||||
|
echo "diff_size=0" >> $GITHUB_OUTPUT
|
||||||
|
fi
|
||||||
|
|
||||||
- name: Analyze code with Claude
|
- name: Analyze code with Claude
|
||||||
if: steps.changed-files.outputs.diff_size != '0'
|
if: steps.changed-files.outputs.diff_size != '0'
|
||||||
@@ -108,7 +122,7 @@ jobs:
|
|||||||
-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 "{
|
-d "{
|
||||||
\"model\": \"claude-3-sonnet-20240229\",
|
\"model\": \"claude-3-sonnet-20241022\",
|
||||||
\"max_tokens\": 4096,
|
\"max_tokens\": 4096,
|
||||||
\"temperature\": 0.7,
|
\"temperature\": 0.7,
|
||||||
\"messages\": [{
|
\"messages\": [{
|
||||||
@@ -117,8 +131,13 @@ jobs:
|
|||||||
}]
|
}]
|
||||||
}")
|
}")
|
||||||
|
|
||||||
# Extract the review content from the response
|
# Extract the review content from the response and handle potential errors
|
||||||
REVIEW=$(echo $RESPONSE | jq -r '.content[0].text')
|
if echo "$RESPONSE" | jq -e '.content[0].text' > /dev/null; then
|
||||||
|
REVIEW=$(echo "$RESPONSE" | jq -r '.content[0].text')
|
||||||
|
else
|
||||||
|
echo "Error in Claude API response: $RESPONSE"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
# Escape the review content for GitHub Actions
|
# Escape the review content for GitHub Actions
|
||||||
REVIEW="${REVIEW//'%'/'%25'}"
|
REVIEW="${REVIEW//'%'/'%25'}"
|
||||||
@@ -134,11 +153,20 @@ jobs:
|
|||||||
with:
|
with:
|
||||||
github-token: ${{ secrets.GITHUB_TOKEN }}
|
github-token: ${{ secrets.GITHUB_TOKEN }}
|
||||||
script: |
|
script: |
|
||||||
|
try {
|
||||||
|
const { owner, repo } = context.repo;
|
||||||
|
const prNumber = ${{ steps.pr-number.outputs.number }};
|
||||||
const review = `${{ steps.analysis.outputs.review }}`;
|
const review = `${{ steps.analysis.outputs.review }}`;
|
||||||
|
|
||||||
|
console.log(`Posting review to PR #${prNumber} in ${owner}/${repo}`);
|
||||||
|
|
||||||
await github.rest.issues.createComment({
|
await github.rest.issues.createComment({
|
||||||
owner: context.repo.owner,
|
owner: owner,
|
||||||
repo: context.repo.name,
|
repo: repo,
|
||||||
issue_number: ${{ steps.pr-number.outputs.number }},
|
issue_number: prNumber,
|
||||||
body: `# Claude Code Review\n\n${review}`
|
body: `# Claude Code Review\n\n${review}`
|
||||||
});
|
});
|
||||||
|
} catch (error) {
|
||||||
|
core.setFailed(`Failed to post review: ${error.message}`);
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user