Skip to content

test

test #4

name: List Open PRs
on:
workflow_dispatch:
pull_request:
branches:
- main
jobs:
list-prs:
name: List Open Pull Requests
runs-on: ubuntu-24.04
permissions:
contents: read
pull-requests: read
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Authenticate to Google Cloud
id: auth
uses: google-github-actions/[email protected]
with:
credentials_json: ${{ secrets.GCP_SERVICE_ACCOUNT_KEY }}
create_credentials_file: true
export_environment_variables: true
env:
# Ensure credentials are created outside the git repository
GOOGLE_APPLICATION_CREDENTIALS_FILE_PATH: /tmp/gcp-credentials.json
- name: Set up Google Cloud SDK
uses: google-github-actions/[email protected]
with:
project_id: ${{ secrets.GCP_PROJECT_ID }}
- name: Install Node.js
uses: actions/[email protected]
with:
node-version: '22'
- name: Install Claude Code
run: |
npm install -g @anthropic-ai/claude-code
echo "Claude Code installed successfully"
- name: Configure Claude Code for Vertex AI
run: |
echo "CLAUDE_CODE_USE_VERTEX=1" >> "$GITHUB_ENV"
echo "CLOUD_ML_REGION=us-east5" >> "$GITHUB_ENV"
echo "ANTHROPIC_VERTEX_PROJECT_ID=${{ secrets.GCP_PROJECT_ID }}" >> "$GITHUB_ENV"
echo "DISABLE_PROMPT_CACHING=1" >> "$GITHUB_ENV"
echo "DISABLE_TELEMETRY=1" >> "$GITHUB_ENV"
echo "DISABLE_ERROR_REPORTING=1" >> "$GITHUB_ENV"
echo "DISABLE_BUG_COMMAND=1" >> "$GITHUB_ENV"
echo "CI=true" >> "$GITHUB_ENV"
echo "TERM=dumb" >> "$GITHUB_ENV"
echo "NO_COLOR=1" >> "$GITHUB_ENV"
echo "FORCE_COLOR=0" >> "$GITHUB_ENV"
echo "DEBIAN_FRONTEND=noninteractive" >> "$GITHUB_ENV"
echo "ANTHROPIC_MODEL=claude-sonnet-4@20250514" >> "$GITHUB_ENV"
- name: List Open Pull Requests with Claude Analysis
shell: bash
run: |
set -euo pipefail
echo "=== Open Pull Requests Analysis by Claude ==="
echo "Repository: ${{ github.repository }}"
echo "Generated at: $(date -u)"
echo ""
# Get open PRs
curl -s \
-H "Authorization: Bearer ${{ github.token }}" \
-H "Accept: application/vnd.github.v3+json" \
"https://api.github.com/repos/${{ github.repository }}/pulls?state=open&per_page=100" \
> open_prs.json
PR_COUNT="$(jq length < open_prs.json)"
echo "Total open PRs: $PR_COUNT"
echo ""
if [ "$PR_COUNT" -eq 0 ]; then
echo "πŸŽ‰ No open pull requests!"
exit 0
fi
# Iterate PRs
jq -c '.[]' open_prs.json | while read -r pr; do
PR_NUMBER="$(jq -r '.number' <<<"$pr")"
PR_TITLE="$(jq -r '.title' <<<"$pr")"
PR_AUTHOR="$(jq -r '.user.login' <<<"$pr")"
PR_URL="$(jq -r '.html_url' <<<"$pr")"
PR_BODY="$(jq -r '.body // "No description provided"' <<<"$pr")"
PR_CREATED="$(jq -r '.created_at' <<<"$pr")"
DRAFT="$(jq -r '.draft' <<<"$pr")"
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo "πŸ”„ PR #$PR_NUMBER: $PR_TITLE"
echo "πŸ‘€ Author: @$PR_AUTHOR"
echo "πŸ”— URL: $PR_URL"
echo "πŸ“… Created: $PR_CREATED"
if [ "$DRAFT" = "true" ]; then
echo "🚧 Status: DRAFT"
else
echo "βœ… Status: Ready for Review"
fi
echo ""
# Get PR diff (not used in prompt, but handy to keep for future)
curl -s \
-H "Authorization: Bearer ${{ github.token }}" \
-H "Accept: application/vnd.github.diff" \
"https://api.github.com/repos/${{ github.repository }}/pulls/$PR_NUMBER" \
> "pr_${PR_NUMBER}.diff"
# Get files changed for context
curl -s \
-H "Authorization: Bearer ${{ github.token }}" \
-H "Accept: application/vnd.github.v3+json" \
"https://api.github.com/repos/${{ github.repository }}/pulls/$PR_NUMBER/files" \
> "pr_${PR_NUMBER}_files.json"
FILES_COUNT="$(jq length < "pr_${PR_NUMBER}_files.json")"
# Create analysis prompt for Claude (unquoted EOF so variables/commands expand)
cat > "claude_prompt_${PR_NUMBER}.txt" <<EOF
Please analyze this pull request and provide a concise summary.

Check failure on line 130 in .github/workflows/claude-code-review.yaml

View workflow run for this annotation

GitHub Actions / .github/workflows/claude-code-review.yaml

Invalid workflow file

You have an error in your yaml syntax on line 130
PR Title: $PR_TITLE
PR Description: $PR_BODY
Files changed: $FILES_COUNT
Key files modified:
$(jq -r '.[] | "- \(.filename) (\(.status)) +\(.additions)/-\(.deletions)"' "pr_${PR_NUMBER}_files.json" | head -10)
Please provide:
1. A brief summary of what this PR does (2-3 sentences)
2. The main technical changes or features added
3. Any potential impact or risks you notice
4. Overall assessment (bug fix, feature, refactor, etc.)
Keep the response concise and focused on the key changes.
EOF
echo "πŸ€– Claude Analysis:"
# Create temp dir outside repo and ensure cleanup
TEMP_DIR="$(mktemp -d "/tmp/claude-pr-${PR_NUMBER}-XXXXXX")"
cp "claude_prompt_${PR_NUMBER}.txt" "$TEMP_DIR/claude_prompt.txt"
pushd "$TEMP_DIR" >/dev/null
CLAUDE_RESPONSE="$(claude -p "$(cat claude_prompt.txt)" --output-format stream-json --verbose 2>&1 | tail -n 20)"
CLAUDE_EXIT=$?
popd >/dev/null
if [ $CLAUDE_EXIT -eq 0 ]; then
echo "$CLAUDE_RESPONSE" | sed 's/^/ /'
else
echo " Claude analysis failed. Error output:"
echo "$CLAUDE_RESPONSE" | sed 's/^/ /'
echo ""
echo " Fallback: Basic analysis based on file changes"
echo " This PR modifies $FILES_COUNT file(s) in the repository."
echo " Manual review recommended for detailed assessment."
fi
# Cleanup temp dir
rm -rf "$TEMP_DIR"
echo ""
echo "πŸ“ Files Summary: $FILES_COUNT file(s) changed"
if [ "$FILES_COUNT" -gt 0 ]; then
jq -r '.[] | " β€’ \(.filename) (\(.status))"' "pr_${PR_NUMBER}_files.json" | head -5
if [ "$FILES_COUNT" -gt 5 ]; then
echo " ... and $((FILES_COUNT - 5)) more files"
fi
fi
echo ""
echo ""
# Clean up per-PR artifacts in repo workspace
rm -f "pr_${PR_NUMBER}.diff" "pr_${PR_NUMBER}_files.json" "claude_prompt_${PR_NUMBER}.txt"
done
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo "🎯 Analysis complete! Found $PR_COUNT open pull request(s) analyzed by Claude."