Skip to content
Closed
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
191 changes: 191 additions & 0 deletions .github/workflows/claude-code-review.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,191 @@
name: List Open PRs

on:
workflow_dispatch:
pull_request:
branches:
- main

jobs:
list-prs:
name: List Open Pull Requests
runs-on: ubuntu-latest

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/auth@v2.1.2

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

View workflow job for this annotation

GitHub Actions / Validate Workflow Changes

1. v2.1.2 is not a valid SHA reference (sha-ref / error) 2. No version comment found (version-comment / warning)

Check warning

Code scanning / CodeQL

Unpinned tag for a non-immutable Action in workflow Medium

Unpinned 3rd party Action 'Claude PR Review' step
Uses Step: auth
uses 'google-github-actions/auth' with ref 'v2.1.2', not a pinned commit hash
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/setup-gcloud@v2.1.0

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

View workflow job for this annotation

GitHub Actions / Validate Workflow Changes

1. v2.1.0 is not a valid SHA reference (sha-ref / error) 2. No version comment found (version-comment / warning)

Check warning

Code scanning / CodeQL

Unpinned tag for a non-immutable Action in workflow Medium

Unpinned 3rd party Action 'Claude PR Review' step
Uses Step
uses 'google-github-actions/setup-gcloud' with ref 'v2.1.0', not a pinned commit hash
with:
project_id: ${{ secrets.GCP_PROJECT_ID }}

- name: Install Node.js
uses: actions/setup-node@v4.0.3
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: |

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

View workflow job for this annotation

GitHub Actions / actionlint

[actionlint] .github/workflows/claude-code-review.yaml#L49

shellcheck reported issue in this script: SC2129:style:1:1: Consider using { cmd1; cmd2; } >> file instead of individual redirects [shellcheck]
Raw output
.github/workflows/claude-code-review.yaml:49:9: shellcheck reported issue in this script: SC2129:style:1:1: Consider using { cmd1; cmd2; } >> file instead of individual redirects [shellcheck]

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

View workflow job for this annotation

GitHub Actions / actionlint

[actionlint] .github/workflows/claude-code-review.yaml#L49

shellcheck reported issue in this script: SC2086:info:1:36: Double quote to prevent globbing and word splitting [shellcheck]
Raw output
.github/workflows/claude-code-review.yaml:49:9: shellcheck reported issue in this script: SC2086:info:1:36: Double quote to prevent globbing and word splitting [shellcheck]

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

View workflow job for this annotation

GitHub Actions / actionlint

[actionlint] .github/workflows/claude-code-review.yaml#L49

shellcheck reported issue in this script: SC2086:info:2:36: Double quote to prevent globbing and word splitting [shellcheck]
Raw output
.github/workflows/claude-code-review.yaml:49:9: shellcheck reported issue in this script: SC2086:info:2:36: Double quote to prevent globbing and word splitting [shellcheck]

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

View workflow job for this annotation

GitHub Actions / actionlint

[actionlint] .github/workflows/claude-code-review.yaml#L49

shellcheck reported issue in this script: SC2086:info:3:69: Double quote to prevent globbing and word splitting [shellcheck]
Raw output
.github/workflows/claude-code-review.yaml:49:9: shellcheck reported issue in this script: SC2086:info:3:69: Double quote to prevent globbing and word splitting [shellcheck]

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

View workflow job for this annotation

GitHub Actions / actionlint

[actionlint] .github/workflows/claude-code-review.yaml#L49

shellcheck reported issue in this script: SC2086:info:4:36: Double quote to prevent globbing and word splitting [shellcheck]
Raw output
.github/workflows/claude-code-review.yaml:49:9: shellcheck reported issue in this script: SC2086:info:4:36: Double quote to prevent globbing and word splitting [shellcheck]

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

View workflow job for this annotation

GitHub Actions / actionlint

[actionlint] .github/workflows/claude-code-review.yaml#L49

shellcheck reported issue in this script: SC2086:info:5:31: Double quote to prevent globbing and word splitting [shellcheck]
Raw output
.github/workflows/claude-code-review.yaml:49:9: shellcheck reported issue in this script: SC2086:info:5:31: Double quote to prevent globbing and word splitting [shellcheck]

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

View workflow job for this annotation

GitHub Actions / actionlint

[actionlint] .github/workflows/claude-code-review.yaml#L49

shellcheck reported issue in this script: SC2086:info:6:37: Double quote to prevent globbing and word splitting [shellcheck]
Raw output
.github/workflows/claude-code-review.yaml:49:9: shellcheck reported issue in this script: SC2086:info:6:37: Double quote to prevent globbing and word splitting [shellcheck]

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

View workflow job for this annotation

GitHub Actions / actionlint

[actionlint] .github/workflows/claude-code-review.yaml#L49

shellcheck reported issue in this script: SC2086:info:7:33: Double quote to prevent globbing and word splitting [shellcheck]
Raw output
.github/workflows/claude-code-review.yaml:49:9: shellcheck reported issue in this script: SC2086:info:7:33: Double quote to prevent globbing and word splitting [shellcheck]

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

View workflow job for this annotation

GitHub Actions / actionlint

[actionlint] .github/workflows/claude-code-review.yaml#L49

shellcheck reported issue in this script: SC2086:info:8:19: Double quote to prevent globbing and word splitting [shellcheck]
Raw output
.github/workflows/claude-code-review.yaml:49:9: shellcheck reported issue in this script: SC2086:info:8:19: Double quote to prevent globbing and word splitting [shellcheck]

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

View workflow job for this annotation

GitHub Actions / actionlint

[actionlint] .github/workflows/claude-code-review.yaml#L49

shellcheck reported issue in this script: SC2086:info:9:21: Double quote to prevent globbing and word splitting [shellcheck]
Raw output
.github/workflows/claude-code-review.yaml:49:9: shellcheck reported issue in this script: SC2086:info:9:21: Double quote to prevent globbing and word splitting [shellcheck]

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

View workflow job for this annotation

GitHub Actions / actionlint

[actionlint] .github/workflows/claude-code-review.yaml#L49

shellcheck reported issue in this script: SC2086:info:10:22: Double quote to prevent globbing and word splitting [shellcheck]
Raw output
.github/workflows/claude-code-review.yaml:49:9: shellcheck reported issue in this script: SC2086:info:10:22: Double quote to prevent globbing and word splitting [shellcheck]

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

View workflow job for this annotation

GitHub Actions / actionlint

[actionlint] .github/workflows/claude-code-review.yaml#L49

shellcheck reported issue in this script: SC2086:info:11:25: Double quote to prevent globbing and word splitting [shellcheck]
Raw output
.github/workflows/claude-code-review.yaml:49:9: shellcheck reported issue in this script: SC2086:info:11:25: Double quote to prevent globbing and word splitting [shellcheck]

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

View workflow job for this annotation

GitHub Actions / actionlint

[actionlint] .github/workflows/claude-code-review.yaml#L49

shellcheck reported issue in this script: SC2086:info:12:42: Double quote to prevent globbing and word splitting [shellcheck]
Raw output
.github/workflows/claude-code-review.yaml:49:9: shellcheck reported issue in this script: SC2086:info:12:42: Double quote to prevent globbing and word splitting [shellcheck]

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

View workflow job for this annotation

GitHub Actions / actionlint

[actionlint] .github/workflows/claude-code-review.yaml#L49

shellcheck reported issue in this script: SC2086:info:13:52: Double quote to prevent globbing and word splitting [shellcheck]
Raw output
.github/workflows/claude-code-review.yaml:49:9: shellcheck reported issue in this script: SC2086:info:13:52: Double quote to prevent globbing and word splitting [shellcheck]
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
run: |

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

View workflow job for this annotation

GitHub Actions / actionlint

[actionlint] .github/workflows/claude-code-review.yaml#L65

shellcheck reported issue in this script: SC1009:info:61:3: The mentioned syntax error was in this simple command [shellcheck]
Raw output
.github/workflows/claude-code-review.yaml:65:9: shellcheck reported issue in this script: SC1009:info:61:3: The mentioned syntax error was in this simple command [shellcheck]

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

View workflow job for this annotation

GitHub Actions / actionlint

[actionlint] .github/workflows/claude-code-review.yaml#L65

shellcheck reported issue in this script: SC1073:error:61:42: Couldn't parse this here document. Fix to allow more checks [shellcheck]
Raw output
.github/workflows/claude-code-review.yaml:65:9: shellcheck reported issue in this script: SC1073:error:61:42: Couldn't parse this here document. Fix to allow more checks [shellcheck]

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

View workflow job for this annotation

GitHub Actions / actionlint

[actionlint] .github/workflows/claude-code-review.yaml#L65

shellcheck reported issue in this script: SC1039:error:78:1: Remove indentation before end token (or use <<- and indent with tabs) [shellcheck]
Raw output
.github/workflows/claude-code-review.yaml:65:9: shellcheck reported issue in this script: SC1039:error:78:1: Remove indentation before end token (or use <<- and indent with tabs) [shellcheck]

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

View workflow job for this annotation

GitHub Actions / actionlint

[actionlint] .github/workflows/claude-code-review.yaml#L65

shellcheck reported issue in this script: SC1072:error:128:1: Here document was not correctly terminated. Fix any mentioned problems and try again [shellcheck]
Raw output
.github/workflows/claude-code-review.yaml:65:9: shellcheck reported issue in this script: SC1072:error:128:1: Here document was not correctly terminated. Fix any mentioned problems and try again [shellcheck]
echo "=== Open Pull Requests Analysis by Claude ==="
echo "Repository: ${{ github.repository }}"
echo "Generated at: $(date)"
echo ""

# Get open PRs
curl -s \
-H "Authorization: token ${{ secrets.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=$(cat open_prs.json | jq length)
echo "Total open PRs: $PR_COUNT"
echo ""

if [ "$PR_COUNT" -eq 0 ]; then
echo "🎉 No open pull requests!"
exit 0
fi

# Process each PR with Claude analysis
cat open_prs.json | jq -c '.[]' | while read -r pr; do
PR_NUMBER=$(echo "$pr" | jq -r '.number')
PR_TITLE=$(echo "$pr" | jq -r '.title')
PR_AUTHOR=$(echo "$pr" | jq -r '.user.login')
PR_URL=$(echo "$pr" | jq -r '.html_url')
PR_BODY=$(echo "$pr" | jq -r '.body // "No description provided"')
PR_CREATED=$(echo "$pr" | jq -r '.created_at')
DRAFT=$(echo "$pr" | jq -r '.draft')

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 for Claude analysis
curl -s \
-H "Authorization: token ${{ secrets.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: token ${{ secrets.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=$(cat "pr_${PR_NUMBER}_files.json" | jq length)

# Create analysis prompt for Claude
cat > "claude_prompt_${PR_NUMBER}.txt" << EOF
Please analyze this pull request and provide a concise summary.

PR Title: $PR_TITLE
PR Description: $PR_BODY
Files changed: $FILES_COUNT

Key files modified:
$(cat "pr_${PR_NUMBER}_files.json" | jq -r '.[] | "- \(.filename) (\(.status)) +\(.additions)/-\(.deletions)"' | 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 directory outside git repository for Claude prompt
TEMP_DIR="/tmp/claude-pr-${PR_NUMBER}-$$"
mkdir -p "$TEMP_DIR"

# Move the prompt to temp directory
mv "claude_prompt_${PR_NUMBER}.txt" "$TEMP_DIR/claude_prompt.txt"

# Use Claude Code CLI with Vertex AI configuration
cd "$TEMP_DIR"
CLAUDE_RESPONSE=$(claude -p "$(cat claude_prompt.txt)" --output-format stream-json --verbose 2>&1 | tail -n 20)
cd - > /dev/null

if [ $? -eq 0 ]; then
# Claude succeeded - display the response
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 directory
rm -rf "$TEMP_DIR"

echo ""
echo "📁 Files Summary: $FILES_COUNT file(s) changed"
if [ "$FILES_COUNT" -gt 0 ]; then
cat "pr_${PR_NUMBER}_files.json" | jq -r '.[] | " • \(.filename) (\(.status))"' | head -5
if [ "$FILES_COUNT" -gt 5 ]; then
echo " ... and $((FILES_COUNT - 5)) more files"
fi
fi

echo ""
echo ""

# Clean up temp files
rm -f "pr_${PR_NUMBER}.diff" "pr_${PR_NUMBER}_files.json"
done

echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo "🎯 Analysis complete! Found $PR_COUNT open pull request(s) analyzed by Claude."
Loading