Skip to content

Commit 672c8ca

Browse files
committed
Merge remote-tracking branch 'origin/main' into new-issue-1872
Signed-off-by: Chen-Rong-Zi <1398881912@qq.com>
2 parents a2fa4c6 + 6cedf32 commit 672c8ca

File tree

22 files changed

+961
-248
lines changed

22 files changed

+961
-248
lines changed

.github/workflows/claude-review.yml

Lines changed: 32 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -63,74 +63,44 @@ jobs:
6363
)
6464
6565
steps:
66+
# Checkout PR Branch (for comments)
67+
- name: Resolve PR Ref
68+
id: resolve-pr-ref
69+
if: github.event_name == 'issue_comment' && github.event.issue.pull_request
70+
env:
71+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
72+
run: |
73+
PR_NUMBER=${{ github.event.issue.number }}
74+
echo "Resolving HEAD SHA for PR #$PR_NUMBER..."
75+
PR_SHA=$(gh pr view $PR_NUMBER --repo ${{ github.repository }} --json headRefOid -q .headRefOid)
76+
echo "Resolved SHA: $PR_SHA"
77+
echo "pr_sha=$PR_SHA" >> $GITHUB_OUTPUT
78+
6679
# Checkout the repository at the appropriate commit for review
6780
- name: Checkout repository
68-
uses: actions/checkout@v4
81+
uses: actions/checkout@v6
6982
with:
70-
# Use PR head SHA for pull_request_target, fallback to current SHA otherwise
71-
fetch-depth: 0
72-
ref: ${{ github.event_name == 'pull_request_target' && github.event.pull_request.head.sha || github.sha }}
73-
74-
# Handle fork branches for pull_request_target events
75-
- name: Setup Fork Remote (for pull_request_target)
76-
if: ${{ github.event_name == 'pull_request_target' }}
77-
env:
78-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
79-
PR_NUMBER: ${{ github.event.pull_request.number }}
80-
PR_HEAD_REF: ${{ github.event.pull_request.head.ref }}
81-
PR_HEAD_OWNER: ${{ github.event.pull_request.head.repo.owner.login }}
82-
PR_HEAD_REPO: ${{ github.event.pull_request.head.repo.name }}
83-
REPO_OWNER: ${{ github.repository_owner }}
84-
run: |
85-
PR_NUMBER="$PR_NUMBER"
86-
HEAD_REF="$PR_HEAD_REF"
87-
HEAD_OWNER="$PR_HEAD_OWNER"
88-
HEAD_REPO="$PR_HEAD_REPO"
89-
CURRENT_OWNER="$REPO_OWNER"
90-
91-
# For forked PRs, temporarily change origin URL to fork repository
92-
# This allows claude-code-action to fetch the PR branch correctly
93-
if [ "$HEAD_OWNER" != "$CURRENT_OWNER" ]; then
94-
echo "PR is from fork: $HEAD_OWNER/$HEAD_REPO"
95-
FORK_URL="https://github.com/$HEAD_OWNER/$HEAD_REPO.git"
96-
echo "Temporarily changing origin URL to fork: $FORK_URL"
97-
git remote set-url origin "$FORK_URL"
98-
git fetch origin "$HEAD_REF"
99-
git branch "$HEAD_REF" "origin/$HEAD_REF" 2>/dev/null || git branch -f "$HEAD_REF" "origin/$HEAD_REF"
100-
fi
101-
102-
# For comment-driven triggers, ensure we have the correct PR branch checked out
103-
- name: Checkout PR Branch (for comments)
104-
if: ${{ github.event_name == 'issue_comment' || github.event_name == 'pull_request_review_comment' }}
105-
env:
106-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
83+
# Use PR head SHA for pull_request_target to review the actual PR code
84+
# For comment events, this will default to the base branch (PR context is inferred by Claude action)
85+
ref: ${{ steps.resolve-pr-ref.outputs.pr_sha || github.event.pull_request.head.sha || github.sha }}
86+
fetch-depth: 20
87+
88+
# Fix git ref access for claude-code-action PR branch checkout
89+
# The action internally runs: git fetch origin pull/N/head:pr-N
90+
# This can fail for two reasons:
91+
# 1. Under git protocol v2, refs/pull/* may not be discoverable if not in
92+
# the configured fetch refspec (causes "couldn't find remote ref")
93+
# 2. If a local branch pr-N already exists and is checked out, git refuses
94+
# to fetch into it (causes "refusing to fetch into branch")
95+
# Adding refs/pull/*/head to the fetch refspec solves issue 1, and we avoid
96+
# creating local branches to prevent issue 2.
97+
- name: Configure git for PR ref access
10798
run: |
108-
PR_NUMBER=${{ github.event.issue.number || github.event.pull_request.number }}
109-
110-
# Fetch PR metadata: head branch name and source repository
111-
PR_DATA=$(gh pr view $PR_NUMBER --json headRefName,headRepositoryOwner,headRepository,baseRefName)
112-
HEAD_REF=$(echo "$PR_DATA" | jq -r '.headRefName')
113-
HEAD_OWNER=$(echo "$PR_DATA" | jq -r '.headRepositoryOwner.login')
114-
HEAD_REPO=$(echo "$PR_DATA" | jq -r '.headRepository.name')
115-
BASE_BRANCH=$(echo "$PR_DATA" | jq -r '.baseRefName')
116-
CURRENT_OWNER="${{ github.repository_owner }}"
117-
118-
# For forked PRs, temporarily change origin URL to fork repository
119-
# This allows claude-code-action to fetch the PR branch correctly
120-
if [ "$HEAD_OWNER" != "$CURRENT_OWNER" ]; then
121-
echo "PR is from fork: $HEAD_OWNER/$HEAD_REPO"
122-
FORK_URL="https://github.com/$HEAD_OWNER/$HEAD_REPO.git"
123-
echo "Temporarily changing origin URL to fork: $FORK_URL"
124-
git remote set-url origin "$FORK_URL"
125-
fi
126-
127-
# Fetch and checkout the PR branch
128-
git fetch origin "$HEAD_REF"
129-
git branch "$HEAD_REF" "origin/$HEAD_REF" 2>/dev/null || git branch -f "$HEAD_REF" "origin/$HEAD_REF"
130-
git checkout "$HEAD_REF"
99+
git config --add remote.origin.fetch '+refs/pull/*/head:refs/remotes/origin/pull/*/head'
131100
132101
# Invoke Claude to perform an automated PR review with progress tracking
133-
- name: PR Review with Progress Tracking
102+
- name: Run Claude Code Review
103+
id: claude-review
134104
uses: anthropics/claude-code-action@v1
135105
with:
136106
anthropic_api_key: ${{ secrets.ANTHROPIC_API_KEY }}
@@ -176,4 +146,3 @@ jobs:
176146
# Restrict tools that Claude can use during the review
177147
claude_args: |
178148
--allowedTools "mcp__github_inline_comment__create_inline_comment,Bash(gh pr comment:*),Bash(gh pr diff:*),Bash(gh pr view:*)"
179-

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ smallvec = "1.15.1"
8181
bytes = "1.11.1"
8282
chrono = { version = "0.4.43", features = ["serde"] }
8383
hex = "0.4.3"
84+
sha1 = "0.10"
8485
sha2 = "0.10.9"
8586

8687
idgenerator = "2.0.0"

ceres/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ tokio-util = { workspace = true }
4444
uuid = { workspace = true, features = ["v4"] }
4545
redis = { workspace = true }
4646
bincode = { workspace = true }
47+
sha1 = { workspace = true }
48+
hex = { workspace = true }
4749

4850
[dev-dependencies]
4951
tempfile = { workspace = true }

0 commit comments

Comments
 (0)