Skip to content

Commit dc3ffea

Browse files
Copilotastandrik
andcommitted
Fix Claude code review workflows to checkout PR head commit
Co-authored-by: astandrik <[email protected]>
1 parent 3814e01 commit dc3ffea

File tree

2 files changed

+38
-6
lines changed

2 files changed

+38
-6
lines changed

.github/workflows/claude-code-review.yml

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ jobs:
99
claude-review:
1010
if: |
1111
github.event_name == 'workflow_dispatch' ||
12-
(github.event_name == 'issue_comment' &&
13-
github.event.issue.pull_request &&
12+
(github.event_name == 'issue_comment' &&
13+
github.event.issue.pull_request &&
1414
contains(github.event.comment.body, '/claude_review'))
1515
1616
runs-on: ubuntu-latest
@@ -21,10 +21,26 @@ jobs:
2121
id-token: write
2222

2323
steps:
24+
- name: Get PR details
25+
id: pr-details
26+
if: github.event_name == 'issue_comment'
27+
env:
28+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
29+
run: |
30+
PR_NUMBER="${{ github.event.issue.number }}"
31+
PR_DATA=$(curl -s -H "Authorization: Bearer $GITHUB_TOKEN" \
32+
"https://api.github.com/repos/${{ github.repository }}/pulls/${PR_NUMBER}")
33+
PR_HEAD_SHA=$(echo "$PR_DATA" | jq -r '.head.sha')
34+
echo "pr_head_sha=$PR_HEAD_SHA" >> $GITHUB_OUTPUT
35+
echo "pr_number=$PR_NUMBER" >> $GITHUB_OUTPUT
36+
2437
- name: Checkout repository
2538
uses: actions/checkout@v4
2639
with:
27-
fetch-depth: 1
40+
# For workflow_dispatch, checkout default branch
41+
# For issue_comment on PR, checkout the PR head commit
42+
ref: ${{ github.event_name == 'issue_comment' && steps.pr-details.outputs.pr_head_sha || github.ref }}
43+
fetch-depth: 0
2844

2945
- name: Run Claude Code Review
3046
id: claude-review

.github/workflows/claude.yml

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ jobs:
99
claude:
1010
if: |
1111
github.event_name == 'workflow_dispatch' ||
12-
(github.event_name == 'issue_comment' &&
13-
github.event.issue.pull_request &&
12+
(github.event_name == 'issue_comment' &&
13+
github.event.issue.pull_request &&
1414
contains(github.event.comment.body, '@claude'))
1515
runs-on: ubuntu-latest
1616
permissions:
@@ -20,10 +20,26 @@ jobs:
2020
id-token: write
2121
actions: read # Required for Claude to read CI results on PRs
2222
steps:
23+
- name: Get PR details
24+
id: pr-details
25+
if: github.event_name == 'issue_comment'
26+
env:
27+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
28+
run: |
29+
PR_NUMBER="${{ github.event.issue.number }}"
30+
PR_DATA=$(curl -s -H "Authorization: Bearer $GITHUB_TOKEN" \
31+
"https://api.github.com/repos/${{ github.repository }}/pulls/${PR_NUMBER}")
32+
PR_HEAD_SHA=$(echo "$PR_DATA" | jq -r '.head.sha')
33+
echo "pr_head_sha=$PR_HEAD_SHA" >> $GITHUB_OUTPUT
34+
echo "pr_number=$PR_NUMBER" >> $GITHUB_OUTPUT
35+
2336
- name: Checkout repository
2437
uses: actions/checkout@v4
2538
with:
26-
fetch-depth: 1
39+
# For workflow_dispatch, checkout default branch
40+
# For issue_comment on PR, checkout the PR head commit
41+
ref: ${{ github.event_name == 'issue_comment' && steps.pr-details.outputs.pr_head_sha || github.ref }}
42+
fetch-depth: 0
2743

2844
- name: Run Claude Code
2945
id: claude

0 commit comments

Comments
 (0)