99jobs :
1010 list-prs :
1111 name : List Open Pull Requests
12- runs-on : ubuntu-latest
12+ runs-on : ubuntu-24.04
1313
1414 permissions :
1515 contents : read
@@ -47,35 +47,38 @@ jobs:
4747
4848 - name : Configure Claude Code for Vertex AI
4949 run : |
50- echo "CLAUDE_CODE_USE_VERTEX=1" >> $GITHUB_ENV
51- echo "CLOUD_ML_REGION=us-east5" >> $GITHUB_ENV
52- echo "ANTHROPIC_VERTEX_PROJECT_ID=${{ secrets.GCP_PROJECT_ID }}" >> $GITHUB_ENV
53- echo "DISABLE_PROMPT_CACHING=1" >> $GITHUB_ENV
54- echo "DISABLE_TELEMETRY=1" >> $GITHUB_ENV
55- echo "DISABLE_ERROR_REPORTING=1" >> $GITHUB_ENV
56- echo "DISABLE_BUG_COMMAND=1" >> $GITHUB_ENV
57- echo "CI=true" >> $GITHUB_ENV
58- echo "TERM=dumb" >> $GITHUB_ENV
59- echo "NO_COLOR=1" >> $GITHUB_ENV
60- echo "FORCE_COLOR=0" >> $GITHUB_ENV
61- echo "DEBIAN_FRONTEND=noninteractive" >> $GITHUB_ENV
62- echo "ANTHROPIC_MODEL=claude-sonnet-4@20250514" >> $GITHUB_ENV
50+ echo "CLAUDE_CODE_USE_VERTEX=1" >> " $GITHUB_ENV"
51+ echo "CLOUD_ML_REGION=us-east5" >> " $GITHUB_ENV"
52+ echo "ANTHROPIC_VERTEX_PROJECT_ID=${{ secrets.GCP_PROJECT_ID }}" >> " $GITHUB_ENV"
53+ echo "DISABLE_PROMPT_CACHING=1" >> " $GITHUB_ENV"
54+ echo "DISABLE_TELEMETRY=1" >> " $GITHUB_ENV"
55+ echo "DISABLE_ERROR_REPORTING=1" >> " $GITHUB_ENV"
56+ echo "DISABLE_BUG_COMMAND=1" >> " $GITHUB_ENV"
57+ echo "CI=true" >> " $GITHUB_ENV"
58+ echo "TERM=dumb" >> " $GITHUB_ENV"
59+ echo "NO_COLOR=1" >> " $GITHUB_ENV"
60+ echo "FORCE_COLOR=0" >> " $GITHUB_ENV"
61+ echo "DEBIAN_FRONTEND=noninteractive" >> " $GITHUB_ENV"
62+ echo "ANTHROPIC_MODEL=claude-sonnet-4@20250514" >> " $GITHUB_ENV"
6363
6464 - name : List Open Pull Requests with Claude Analysis
65+ shell : bash
6566 run : |
67+ set -euo pipefail
68+
6669 echo "=== Open Pull Requests Analysis by Claude ==="
6770 echo "Repository: ${{ github.repository }}"
68- echo "Generated at: $(date)"
71+ echo "Generated at: $(date -u )"
6972 echo ""
7073
7174 # Get open PRs
7275 curl -s \
73- -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
76+ -H "Authorization: Bearer ${{ github.token }}" \
7477 -H "Accept: application/vnd.github.v3+json" \
7578 "https://api.github.com/repos/${{ github.repository }}/pulls?state=open&per_page=100" \
7679 > open_prs.json
7780
78- PR_COUNT=$(cat open_prs.json | jq length)
81+ PR_COUNT="$(jq length < open_prs.json)"
7982 echo "Total open PRs: $PR_COUNT"
8083 echo ""
8184
@@ -84,80 +87,76 @@ jobs:
8487 exit 0
8588 fi
8689
87- # Process each PR with Claude analysis
88- cat open_prs.json | jq -c '.[]' | while read -r pr; do
89- PR_NUMBER=$(echo "$pr" | jq -r '.number')
90- PR_TITLE=$(echo "$pr" | jq -r '.title')
91- PR_AUTHOR=$(echo "$pr" | jq -r '.user.login')
92- PR_URL=$(echo "$pr" | jq -r '.html_url')
93- PR_BODY=$(echo "$pr" | jq -r '.body // "No description provided"')
94- PR_CREATED=$(echo "$pr" | jq -r '.created_at')
95- DRAFT=$(echo "$pr" | jq -r '.draft')
90+ # Iterate PRs
91+ jq -c '.[]' open_prs.json | while read -r pr; do
92+ PR_NUMBER="$( jq -r '.number' <<<"$pr")"
93+ PR_TITLE="$( jq -r '.title' <<<"$pr")"
94+ PR_AUTHOR="$( jq -r '.user.login' <<<"$pr")"
95+ PR_URL="$( jq -r '.html_url' <<<"$pr")"
96+ PR_BODY="$( jq -r '.body // "No description provided"' <<<"$pr")"
97+ PR_CREATED="$( jq -r '.created_at' <<<"$pr")"
98+ DRAFT="$( jq -r '.draft' <<<"$pr")"
9699
97100 echo "βββββββββββββββββββββββββββββββββββββββββββββββββββ"
98101 echo "π PR #$PR_NUMBER: $PR_TITLE"
99102 echo "π€ Author: @$PR_AUTHOR"
100103 echo "π URL: $PR_URL"
101104 echo "π
Created: $PR_CREATED"
102- if [ "$DRAFT" == "true" ]; then
105+ if [ "$DRAFT" = "true" ]; then
103106 echo "π§ Status: DRAFT"
104107 else
105108 echo "β
Status: Ready for Review"
106109 fi
107110 echo ""
108111
109- # Get PR diff for Claude analysis
112+ # Get PR diff (not used in prompt, but handy to keep for future)
110113 curl -s \
111- -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
114+ -H "Authorization: Bearer ${{ github.token }}" \
112115 -H "Accept: application/vnd.github.diff" \
113116 "https://api.github.com/repos/${{ github.repository }}/pulls/$PR_NUMBER" \
114117 > "pr_${PR_NUMBER}.diff"
115118
116119 # Get files changed for context
117120 curl -s \
118- -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
121+ -H "Authorization: Bearer ${{ github.token }}" \
119122 -H "Accept: application/vnd.github.v3+json" \
120123 "https://api.github.com/repos/${{ github.repository }}/pulls/$PR_NUMBER/files" \
121124 > "pr_${PR_NUMBER}_files.json"
122125
123- FILES_COUNT=$(cat "pr_${PR_NUMBER}_files.json" | jq length)
126+ FILES_COUNT="$(jq length < "pr_${PR_NUMBER}_files.json")"
124127
125- # Create analysis prompt for Claude
126- cat > "claude_prompt_${PR_NUMBER}.txt" << 'PROMPT_EOF'
127- Please analyze this pull request and provide a concise summary.
128+ # Create analysis prompt for Claude (unquoted EOF so variables/commands expand)
129+ cat > "claude_prompt_${PR_NUMBER}.txt" <<EOF
130+ Please analyze this pull request and provide a concise summary.
128131
129- PR Title: $PR_TITLE
130- PR Description: $PR_BODY
131- Files changed: $FILES_COUNT
132+ PR Title : $PR_TITLE
133+ PR Description : $PR_BODY
134+ Files changed : $FILES_COUNT
132135
133- Key files modified:
134- \$(cat "pr_${PR_NUMBER}_files.json" | jq -r '.[] | "- \(.filename) (\(.status)) +\(.additions)/-\(.deletions)"' | head -10)
136+ Key files modified :
137+ $( jq -r '.[] | "- \(.filename) (\(.status)) +\(.additions)/-\(.deletions)"' "pr_${PR_NUMBER}_files.json" | head -10)
135138
136- Please provide:
137- 1. A brief summary of what this PR does (2-3 sentences)
138- 2. The main technical changes or features added
139- 3. Any potential impact or risks you notice
140- 4. Overall assessment (bug fix, feature, refactor, etc.)
139+ Please provide :
140+ 1. A brief summary of what this PR does (2-3 sentences)
141+ 2. The main technical changes or features added
142+ 3. Any potential impact or risks you notice
143+ 4. Overall assessment (bug fix, feature, refactor, etc.)
141144
142- Keep the response concise and focused on the key changes.
143- PROMPT_EOF
145+ Keep the response concise and focused on the key changes.
146+ EOF
144147
145148 echo "π€ Claude Analysis:"
146149
147- # Create temp directory outside git repository for Claude prompt
148- TEMP_DIR="/tmp/claude-pr-${PR_NUMBER}-$$"
149- mkdir -p "$TEMP_DIR"
150-
151- # Move the prompt to temp directory
152- mv "claude_prompt_${PR_NUMBER}.txt" "$TEMP_DIR/claude_prompt.txt"
150+ # Create temp dir outside repo and ensure cleanup
151+ TEMP_DIR="$(mktemp -d "/tmp/claude-pr-${PR_NUMBER}-XXXXXX")"
152+ cp "claude_prompt_${PR_NUMBER}.txt" "$TEMP_DIR/claude_prompt.txt"
153153
154- # Use Claude Code CLI with Vertex AI configuration
155- cd "$TEMP_DIR "
156- CLAUDE_RESPONSE=$(claude -p "$(cat claude_prompt.txt)" --output-format stream-json --verbose 2>&1 | tail -n 20)
157- cd - > /dev/null
154+ pushd "$TEMP_DIR" >/dev/null
155+ CLAUDE_RESPONSE="$(claude -p "$(cat claude_prompt.txt)" --output-format stream-json --verbose 2>&1 | tail -n 20) "
156+ CLAUDE_EXIT=$?
157+ popd > /dev/null
158158
159- if [ $? -eq 0 ]; then
160- # Claude succeeded - display the response
159+ if [ $CLAUDE_EXIT -eq 0 ]; then
161160 echo "$CLAUDE_RESPONSE" | sed 's/^/ /'
162161 else
163162 echo " Claude analysis failed. Error output:"
@@ -168,13 +167,13 @@ jobs:
168167 echo " Manual review recommended for detailed assessment."
169168 fi
170169
171- # Cleanup temp directory
170+ # Cleanup temp dir
172171 rm -rf "$TEMP_DIR"
173172
174173 echo ""
175174 echo "π Files Summary : $FILES_COUNT file(s) changed"
176175 if [ "$FILES_COUNT" -gt 0 ]; then
177- cat "pr_${PR_NUMBER}_files.json" | jq -r '.[] | " β’ \(.filename) (\(.status))"' | head -5
176+ jq -r '.[] | " β’ \(.filename) (\(.status))"' "pr_${PR_NUMBER}_files.json" | head -5
178177 if [ "$FILES_COUNT" -gt 5 ]; then
179178 echo " ... and $((FILES_COUNT - 5)) more files"
180179 fi
@@ -183,8 +182,8 @@ jobs:
183182 echo ""
184183 echo ""
185184
186- # Clean up temp files
187- rm -f "pr_${PR_NUMBER}.diff" "pr_${PR_NUMBER}_files.json"
185+ # Clean up per-PR artifacts in repo workspace
186+ rm -f "pr_${PR_NUMBER}.diff" "pr_${PR_NUMBER}_files.json" "claude_prompt_${PR_NUMBER}.txt"
188187 done
189188
190189 echo "βββββββββββββββββββββββββββββββββββββββββββββββββββ"
0 commit comments