From 55eca6c50f28283206d651b6acdcec09e8e1c7fd Mon Sep 17 00:00:00 2001 From: bytesizedroll Date: Mon, 8 Sep 2025 20:44:29 +0200 Subject: [PATCH 1/8] test workflow --- .github/workflows/claude-code-review.yaml | 188 ++++++++++++++++++++++ 1 file changed, 188 insertions(+) create mode 100644 .github/workflows/claude-code-review.yaml diff --git a/.github/workflows/claude-code-review.yaml b/.github/workflows/claude-code-review.yaml new file mode 100644 index 00000000..9253477c --- /dev/null +++ b/.github/workflows/claude-code-review.yaml @@ -0,0 +1,188 @@ +name: List Open PRs + +on: + workflow_dispatch: + +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 + 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 + 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: | + 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: | + 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." From 15576954b3e59415bf905519a7f5279a70d1a589 Mon Sep 17 00:00:00 2001 From: bytesizedroll Date: Mon, 8 Sep 2025 20:44:58 +0200 Subject: [PATCH 2/8] register with pr for workflow --- .github/workflows/claude-code-review.yaml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/claude-code-review.yaml b/.github/workflows/claude-code-review.yaml index 9253477c..2d08c31a 100644 --- a/.github/workflows/claude-code-review.yaml +++ b/.github/workflows/claude-code-review.yaml @@ -2,6 +2,9 @@ name: List Open PRs on: workflow_dispatch: + pull_request: + branches: + - main jobs: list-prs: From 45348498384f7f4759ebb1689d838a80a70dbef8 Mon Sep 17 00:00:00 2001 From: bytesizedroll Date: Mon, 8 Sep 2025 20:48:00 +0200 Subject: [PATCH 3/8] heredoc stuff --- .github/workflows/claude-code-review.yaml | 26 +++++++++++------------ 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/.github/workflows/claude-code-review.yaml b/.github/workflows/claude-code-review.yaml index 2d08c31a..1388faf3 100644 --- a/.github/workflows/claude-code-review.yaml +++ b/.github/workflows/claude-code-review.yaml @@ -124,23 +124,23 @@ jobs: # Create analysis prompt for Claude cat > "claude_prompt_${PR_NUMBER}.txt" << EOF - Please analyze this pull request and provide a concise summary. +Please analyze this pull request and provide a concise summary. - PR Title: $PR_TITLE - PR Description: $PR_BODY - Files changed: $FILES_COUNT +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) +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.) +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 +Keep the response concise and focused on the key changes. +EOF echo "🤖 Claude Analysis:" From 59fa6db2b94a76ce9d33009e1ac0dcdbb3bc04df Mon Sep 17 00:00:00 2001 From: bytesizedroll Date: Mon, 8 Sep 2025 20:49:43 +0200 Subject: [PATCH 4/8] test --- .github/workflows/claude-code-review.yaml | 28 +++++++++++------------ 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/.github/workflows/claude-code-review.yaml b/.github/workflows/claude-code-review.yaml index 1388faf3..c1fe6a46 100644 --- a/.github/workflows/claude-code-review.yaml +++ b/.github/workflows/claude-code-review.yaml @@ -123,24 +123,24 @@ jobs: 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. + cat > "claude_prompt_${PR_NUMBER}.txt" << 'PROMPT_EOF' + Please analyze this pull request and provide a concise summary. -PR Title: $PR_TITLE -PR Description: $PR_BODY -Files changed: $FILES_COUNT + 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) + 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.) + 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 + Keep the response concise and focused on the key changes. + PROMPT_EOF echo "🤖 Claude Analysis:" From 32460e097eb72887ff0fd6b73e6b146b8b60361f Mon Sep 17 00:00:00 2001 From: bytesizedroll Date: Mon, 8 Sep 2025 20:54:56 +0200 Subject: [PATCH 5/8] test --- .github/workflows/claude-code-review.yaml | 123 +++++++++++----------- 1 file changed, 61 insertions(+), 62 deletions(-) diff --git a/.github/workflows/claude-code-review.yaml b/.github/workflows/claude-code-review.yaml index c1fe6a46..cf6f74ef 100644 --- a/.github/workflows/claude-code-review.yaml +++ b/.github/workflows/claude-code-review.yaml @@ -9,7 +9,7 @@ on: jobs: list-prs: name: List Open Pull Requests - runs-on: ubuntu-latest + runs-on: ubuntu-24.04 permissions: contents: read @@ -47,35 +47,38 @@ jobs: - 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 + 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)" + echo "Generated at: $(date -u)" echo "" # Get open PRs curl -s \ - -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \ + -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=$(cat open_prs.json | jq length) + PR_COUNT="$(jq length < open_prs.json)" echo "Total open PRs: $PR_COUNT" echo "" @@ -84,80 +87,76 @@ jobs: 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') + # 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 + if [ "$DRAFT" = "true" ]; then echo "🚧 Status: DRAFT" else echo "✅ Status: Ready for Review" fi echo "" - # Get PR diff for Claude analysis + # Get PR diff (not used in prompt, but handy to keep for future) curl -s \ - -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \ + -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: token ${{ secrets.GITHUB_TOKEN }}" \ + -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=$(cat "pr_${PR_NUMBER}_files.json" | jq length) + FILES_COUNT="$(jq length < "pr_${PR_NUMBER}_files.json")" - # Create analysis prompt for Claude - cat > "claude_prompt_${PR_NUMBER}.txt" << 'PROMPT_EOF' - Please analyze this pull request and provide a concise summary. + # Create analysis prompt for Claude (unquoted EOF so variables/commands expand) + cat > "claude_prompt_${PR_NUMBER}.txt" <&1 | tail -n 20) - cd - > /dev/null + 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 [ $? -eq 0 ]; then - # Claude succeeded - display the response + if [ $CLAUDE_EXIT -eq 0 ]; then echo "$CLAUDE_RESPONSE" | sed 's/^/ /' else echo " Claude analysis failed. Error output:" @@ -168,13 +167,13 @@ jobs: echo " Manual review recommended for detailed assessment." fi - # Cleanup temp directory + # Cleanup temp dir 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 + 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 @@ -183,8 +182,8 @@ jobs: echo "" echo "" - # Clean up temp files - rm -f "pr_${PR_NUMBER}.diff" "pr_${PR_NUMBER}_files.json" + # 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 "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━" From 67f4b7100dd2feb0fc6b9e95bbec97100b5a4fb5 Mon Sep 17 00:00:00 2001 From: bytesizedroll Date: Mon, 8 Sep 2025 21:04:36 +0200 Subject: [PATCH 6/8] test --- .github/workflows/claude-code-review.yaml | 129 +++++++++++----------- 1 file changed, 62 insertions(+), 67 deletions(-) diff --git a/.github/workflows/claude-code-review.yaml b/.github/workflows/claude-code-review.yaml index cf6f74ef..5d0b96ef 100644 --- a/.github/workflows/claude-code-review.yaml +++ b/.github/workflows/claude-code-review.yaml @@ -27,7 +27,6 @@ jobs: 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 @@ -47,19 +46,21 @@ jobs: - 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" + { + echo "CLAUDE_CODE_USE_VERTEX=1" + echo "CLOUD_ML_REGION=us-east5" + echo "ANTHROPIC_VERTEX_PROJECT_ID=${{ secrets.GCP_PROJECT_ID }}" + echo "DISABLE_PROMPT_CACHING=1" + echo "DISABLE_TELEMETRY=1" + echo "DISABLE_ERROR_REPORTING=1" + echo "DISABLE_BUG_COMMAND=1" + echo "CI=true" + echo "TERM=dumb" + echo "NO_COLOR=1" + echo "FORCE_COLOR=0" + echo "DEBIAN_FRONTEND=noninteractive" + echo "ANTHROPIC_MODEL=claude-sonnet-4@20250514" + } >> "$GITHUB_ENV" - name: List Open Pull Requests with Claude Analysis shell: bash @@ -69,7 +70,7 @@ jobs: echo "=== Open Pull Requests Analysis by Claude ===" echo "Repository: ${{ github.repository }}" echo "Generated at: $(date -u)" - echo "" + echo # Get open PRs curl -s \ @@ -80,14 +81,13 @@ jobs: PR_COUNT="$(jq length < open_prs.json)" echo "Total open PRs: $PR_COUNT" - echo "" + echo if [ "$PR_COUNT" -eq 0 ]; then - echo "🎉 No open pull requests!" + 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")" @@ -97,26 +97,26 @@ jobs: 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" + 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" + echo "Status: DRAFT" else - echo "✅ Status: Ready for Review" + echo "Status: Ready for Review" fi - echo "" + echo - # Get PR diff (not used in prompt, but handy to keep for future) + # Get PR diff (optional) 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 + # Get files changed curl -s \ -H "Authorization: Bearer ${{ github.token }}" \ -H "Accept: application/vnd.github.v3+json" \ @@ -125,29 +125,28 @@ jobs: 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" < "claude_prompt_${PR_NUMBER}.txt" - echo "🤖 Claude Analysis:" + 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" @@ -157,34 +156,30 @@ EOF popd >/dev/null if [ $CLAUDE_EXIT -eq 0 ]; then - echo "$CLAUDE_RESPONSE" | sed 's/^/ /' + 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." + 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" + 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 + jq -r '.[] | " • \(.filename) (\(.status))"' "pr_${PR_NUMBER}_files.json" | head -5 if [ "$FILES_COUNT" -gt 5 ]; then - echo " ... and $((FILES_COUNT - 5)) more files" + echo " ... and $((FILES_COUNT - 5)) more files" fi fi - echo "" - echo "" - - # Clean up per-PR artifacts in repo workspace + echo 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." + echo "------------------------------------------------------------" + echo "Analysis complete. Found $PR_COUNT open pull request(s)." From 7130be971730996c73817754aea97e81ff4cff53 Mon Sep 17 00:00:00 2001 From: bytesizedroll Date: Mon, 8 Sep 2025 21:09:18 +0200 Subject: [PATCH 7/8] test --- .github/workflows/claude-code-review.yaml | 61 +++++++++++++++-------- 1 file changed, 40 insertions(+), 21 deletions(-) diff --git a/.github/workflows/claude-code-review.yaml b/.github/workflows/claude-code-review.yaml index 5d0b96ef..e1603033 100644 --- a/.github/workflows/claude-code-review.yaml +++ b/.github/workflows/claude-code-review.yaml @@ -93,7 +93,7 @@ jobs: 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_BODY="$(jq -r '.body // "No description provided"' <<<"$pr" | head -20)" PR_CREATED="$(jq -r '.created_at' <<<"$pr")" DRAFT="$(jq -r '.draft' <<<"$pr")" @@ -127,46 +127,65 @@ jobs: # Create analysis prompt for Claude (ensure expansion happens) { - echo "Please analyze this pull request and provide a concise summary." + echo "Please analyze Pull Request #$PR_NUMBER from the chainlink-deployments-framework repository and provide a concise summary." echo "" - echo "PR Title: $PR_TITLE" - echo "PR Description: $PR_BODY" - echo "Files changed: $FILES_COUNT" + echo "PR Details:" + echo "- Number: #$PR_NUMBER" + echo "- Title: $PR_TITLE" + echo "- Author: @$PR_AUTHOR" + echo "- Status: $([ "$DRAFT" = "true" ] && echo "DRAFT" || echo "Ready for Review")" + echo "- URL: $PR_URL" echo "" - echo "Key files modified:" - jq -r '.[] | "- \(.filename) (\(.status)) +\(.additions)/-\(.deletions)"' "pr_${PR_NUMBER}_files.json" | head -10 + echo "Description:" + if [ -n "$PR_BODY" ] && [ "$PR_BODY" != "No description provided" ]; then + echo "$PR_BODY" + else + echo "No description provided by the author." + fi + echo "" + echo "Files Analysis:" + echo "- Total files changed: $FILES_COUNT" + if [ "$FILES_COUNT" -gt 0 ]; then + echo "- Key files modified:" + jq -r '.[] | " • \(.filename) (\(.status)) +\(.additions)/-\(.deletions) lines"' "pr_${PR_NUMBER}_files.json" | head -10 + fi echo "" - echo "Please provide:" - echo "1. A brief summary of what this PR does (2-3 sentences)" - echo "2. The main technical changes or features added" - echo "3. Any potential impact or risks you notice" - echo "4. Overall assessment (bug fix, feature, refactor, etc.)" + echo "Please provide a focused analysis with:" + echo "1. A brief summary of what this PR accomplishes (2-3 sentences)" + echo "2. The main technical changes or features introduced" + echo "3. Any potential impact, risks, or considerations" + echo "4. Overall category (bug fix, feature, refactor, documentation, etc.)" echo "" - echo "Keep the response concise and focused on the key changes." + echo "Focus on the actual changes made in this specific PR." } > "claude_prompt_${PR_NUMBER}.txt" + # Debug: Show first few lines of prompt to verify variable expansion + echo "Debug - Prompt preview:" + head -8 "claude_prompt_${PR_NUMBER}.txt" | sed 's/^/ /' + echo "Claude Analysis:" 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/^/ /' + if CLAUDE_RESPONSE="$(claude -p "$(cat claude_prompt.txt)" 2>/tmp/claude_error.log)"; then + echo "$CLAUDE_RESPONSE" | sed 's/^/ /' | head -50 else - echo " Claude analysis failed. Error output:" - echo "$CLAUDE_RESPONSE" | sed 's/^/ /' + echo " Claude analysis failed." + if [ -s /tmp/claude_error.log ]; then + echo " Error details:" + head -5 /tmp/claude_error.log | sed 's/^/ /' + fi 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 + popd >/dev/null rm -rf "$TEMP_DIR" + rm -f /tmp/claude_error.log echo echo "Files Summary: $FILES_COUNT file(s) changed" From 5ba28349504e15f7f0051ed26cb46280a19f7a32 Mon Sep 17 00:00:00 2001 From: bytesizedroll Date: Tue, 9 Sep 2025 13:37:39 +0200 Subject: [PATCH 8/8] reveiw on one pr --- .github/workflows/claude-code-review.yaml | 221 ++++++++++------------ 1 file changed, 98 insertions(+), 123 deletions(-) diff --git a/.github/workflows/claude-code-review.yaml b/.github/workflows/claude-code-review.yaml index e1603033..40d4e84a 100644 --- a/.github/workflows/claude-code-review.yaml +++ b/.github/workflows/claude-code-review.yaml @@ -1,14 +1,14 @@ -name: List Open PRs +name: Claude PR Review on: - workflow_dispatch: pull_request: branches: - main + types: [opened, synchronize, reopened] jobs: - list-prs: - name: List Open Pull Requests + review-pr: + name: Analyze Pull Request with Claude runs-on: ubuntu-24.04 permissions: @@ -62,143 +62,118 @@ jobs: echo "ANTHROPIC_MODEL=claude-sonnet-4@20250514" } >> "$GITHUB_ENV" - - name: List Open Pull Requests with Claude Analysis + - name: Analyze Current Pull Request with Claude shell: bash + env: + REPOSITORY: ${{ github.repository }} + PR_NUMBER: ${{ github.event.pull_request.number }} + PR_TITLE: ${{ github.event.pull_request.title }} + PR_AUTHOR: ${{ github.event.pull_request.user.login }} + PR_URL: ${{ github.event.pull_request.html_url }} + PR_BODY: ${{ github.event.pull_request.body }} + DRAFT: ${{ github.event.pull_request.draft }} run: | set -euo pipefail - echo "=== Open Pull Requests Analysis by Claude ===" - echo "Repository: ${{ github.repository }}" + echo "=== Claude PR Analysis ===" + echo "Repository: $REPOSITORY" echo "Generated at: $(date -u)" echo - # Get open PRs + echo "------------------------------------------------------------" + echo "PR #$PR_NUMBER: $PR_TITLE" + echo "Author: @$PR_AUTHOR" + echo "URL: $PR_URL" + if [ "$DRAFT" = "true" ]; then + echo "Status: DRAFT" + else + echo "Status: Ready for Review" + fi + echo + + # Get files changed in this PR 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 + "https://api.github.com/repos/$REPOSITORY/pulls/$PR_NUMBER/files" \ + > "pr_files.json" - PR_COUNT="$(jq length < open_prs.json)" - echo "Total open PRs: $PR_COUNT" - echo + FILES_COUNT="$(jq length < pr_files.json)" - if [ "$PR_COUNT" -eq 0 ]; then - echo "No open pull requests." - exit 0 - fi - - 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" | head -20)" - 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" + # Create analysis prompt for Claude + { + echo "Please analyze Pull Request #$PR_NUMBER from the chainlink-deployments-framework repository and provide a concise summary." + echo "" + echo "PR Details:" + echo "- Number: #$PR_NUMBER" + echo "- Title: $PR_TITLE" + echo "- Author: @$PR_AUTHOR" + echo "- Status: $([ "$DRAFT" = "true" ] && echo "DRAFT" || echo "Ready for Review")" + echo "- URL: $PR_URL" + echo "" + echo "Description:" + if [ -n "$PR_BODY" ] && [ "$PR_BODY" != "null" ]; then + echo "$PR_BODY" | head -20 else - echo "Status: Ready for Review" + echo "No description provided by the author." fi - echo - - # Get PR diff (optional) - 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 - 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 (ensure expansion happens) - { - echo "Please analyze Pull Request #$PR_NUMBER from the chainlink-deployments-framework repository and provide a concise summary." - echo "" - echo "PR Details:" - echo "- Number: #$PR_NUMBER" - echo "- Title: $PR_TITLE" - echo "- Author: @$PR_AUTHOR" - echo "- Status: $([ "$DRAFT" = "true" ] && echo "DRAFT" || echo "Ready for Review")" - echo "- URL: $PR_URL" - echo "" - echo "Description:" - if [ -n "$PR_BODY" ] && [ "$PR_BODY" != "No description provided" ]; then - echo "$PR_BODY" - else - echo "No description provided by the author." - fi - echo "" - echo "Files Analysis:" - echo "- Total files changed: $FILES_COUNT" - if [ "$FILES_COUNT" -gt 0 ]; then - echo "- Key files modified:" - jq -r '.[] | " • \(.filename) (\(.status)) +\(.additions)/-\(.deletions) lines"' "pr_${PR_NUMBER}_files.json" | head -10 - fi - echo "" - echo "Please provide a focused analysis with:" - echo "1. A brief summary of what this PR accomplishes (2-3 sentences)" - echo "2. The main technical changes or features introduced" - echo "3. Any potential impact, risks, or considerations" - echo "4. Overall category (bug fix, feature, refactor, documentation, etc.)" - echo "" - echo "Focus on the actual changes made in this specific PR." - } > "claude_prompt_${PR_NUMBER}.txt" - - # Debug: Show first few lines of prompt to verify variable expansion - echo "Debug - Prompt preview:" - head -8 "claude_prompt_${PR_NUMBER}.txt" | sed 's/^/ /' - - echo "Claude Analysis:" - - 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 - if CLAUDE_RESPONSE="$(claude -p "$(cat claude_prompt.txt)" 2>/tmp/claude_error.log)"; then - echo "$CLAUDE_RESPONSE" | sed 's/^/ /' | head -50 - else - echo " Claude analysis failed." - if [ -s /tmp/claude_error.log ]; then - echo " Error details:" - head -5 /tmp/claude_error.log | sed 's/^/ /' - fi - 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." + echo "" + echo "Files Analysis:" + echo "- Total files changed: $FILES_COUNT" + if [ "$FILES_COUNT" -gt 0 ]; then + echo "- Key files modified:" + jq -r '.[] | " • \(.filename) (\(.status)) +\(.additions)/-\(.deletions) lines"' pr_files.json | head -10 fi - popd >/dev/null + echo "" + echo "Please provide a focused analysis with:" + echo "1. A brief summary of what this PR accomplishes (2-3 sentences)" + echo "2. The main technical changes or features introduced" + echo "3. Any potential impact, risks, or considerations" + echo "4. Overall category (bug fix, feature, refactor, documentation, etc.)" + echo "" + echo "Focus on the actual changes made in this specific PR." + } > "claude_prompt.txt" + + # Debug: Show first few lines of prompt to verify content + echo "Debug - Prompt preview:" + head -8 "claude_prompt.txt" | sed 's/^/ /' + echo - rm -rf "$TEMP_DIR" - rm -f /tmp/claude_error.log + echo "Claude Analysis:" - 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 + TEMP_DIR="$(mktemp -d "/tmp/claude-pr-XXXXXX")" + cp "claude_prompt.txt" "$TEMP_DIR/claude_prompt.txt" + pushd "$TEMP_DIR" >/dev/null + if CLAUDE_RESPONSE="$(claude -p "$(cat claude_prompt.txt)" 2>/tmp/claude_error.log)"; then + echo "$CLAUDE_RESPONSE" | sed 's/^/ /' | head -50 + else + echo " Claude analysis failed." + if [ -s /tmp/claude_error.log ]; then + echo " Error details:" + head -5 /tmp/claude_error.log | sed 's/^/ /' + fi echo - rm -f "pr_${PR_NUMBER}.diff" "pr_${PR_NUMBER}_files.json" "claude_prompt_${PR_NUMBER}.txt" - done + 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 + popd >/dev/null + + rm -rf "$TEMP_DIR" + rm -f /tmp/claude_error.log + echo + echo "Files Summary: $FILES_COUNT file(s) changed" + if [ "$FILES_COUNT" -gt 0 ]; then + jq -r '.[] | " • \(.filename) (\(.status))"' pr_files.json | head -5 + if [ "$FILES_COUNT" -gt 5 ]; then + echo " ... and $((FILES_COUNT - 5)) more files" + fi + fi + + echo echo "------------------------------------------------------------" - echo "Analysis complete. Found $PR_COUNT open pull request(s)." + echo "Analysis complete for PR #$PR_NUMBER" + + rm -f pr_files.json claude_prompt.txt