Skip to content

[r2cn] 实现系统邮件通知中心,并支持用户自定义通知类型配置 #1716

[r2cn] 实现系统邮件通知中心,并支持用户自定义通知类型配置

[r2cn] 实现系统邮件通知中心,并支持用户自定义通知类型配置 #1716

Workflow file for this run

name: Claude Code Review with Progress Tracking
# Trigger Claude review on PR lifecycle events and explicit mentions
on:
# Trigger when a new issue comment is created (for @claude mentions)
issue_comment:
types: [created]
# Trigger when a PR review comment is created/edited/deleted (for @claude mentions)
pull_request_review_comment:
types: [created, edited, deleted]
# Trigger on new or assigned issues (for future extension or automation)
issues:
types: [opened, assigned]
# Trigger when a PR review is submitted (for @claude in the review body)
pull_request_review:
types: [submitted]
# Main trigger for PR events, using pull_request_target for elevated permissions
pull_request_target:
types: [opened, synchronize, reopened]
permissions:
# Read repository contents needed for code review
contents: read
# Allow Claude to post review comments on pull requests
pull-requests: write
# Allow Claude to interact with issues if needed
issues: write
# Allow this workflow to manage its own actions if required
actions: write
jobs:
claude-review-with-tracking:
runs-on: ubuntu-latest
# Only run for trusted authors or when explicitly mentioned by them
if: |
(
github.event_name == 'pull_request_target' &&
(
github.event.pull_request.author_association == 'OWNER' ||
github.event.pull_request.author_association == 'MEMBER' ||
github.event.pull_request.author_association == 'COLLABORATOR'
)
) ||
(
(github.event_name == 'issue_comment' || github.event_name == 'pull_request_review_comment') &&
contains(github.event.comment.body, '@claude') &&
(
github.event.comment.author_association == 'OWNER' ||
github.event.comment.author_association == 'MEMBER' ||
github.event.comment.author_association == 'COLLABORATOR'
)
) ||
(
github.event_name == 'pull_request_review' &&
contains(github.event.review.body, '@claude') &&
(
github.event.review.author_association == 'OWNER' ||
github.event.review.author_association == 'MEMBER' ||
github.event.review.author_association == 'COLLABORATOR'
)
)
steps:
# Checkout PR Branch (for comments)
- name: Resolve PR Ref
id: resolve-pr-ref
if: github.event_name == 'issue_comment' && github.event.issue.pull_request
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
PR_NUMBER=${{ github.event.issue.number }}
echo "Resolving HEAD SHA for PR #$PR_NUMBER..."
PR_SHA=$(gh pr view $PR_NUMBER --repo ${{ github.repository }} --json headRefOid -q .headRefOid)
echo "Resolved SHA: $PR_SHA"
echo "pr_sha=$PR_SHA" >> $GITHUB_OUTPUT
# Checkout the repository at the appropriate commit for review
- name: Checkout repository
uses: actions/checkout@v6
with:
# Use PR head SHA for pull_request_target to review the actual PR code
# For comment events, this will default to the base branch (PR context is inferred by Claude action)
ref: ${{ steps.resolve-pr-ref.outputs.pr_sha || github.event.pull_request.head.sha || github.sha }}
fetch-depth: 20
# Fix git ref access for claude-code-action PR branch checkout
# The action internally runs: git fetch origin pull/N/head:pr-N
# This can fail for two reasons:
# 1. Under git protocol v2, refs/pull/* may not be discoverable if not in
# the configured fetch refspec (causes "couldn't find remote ref")
# 2. If a local branch pr-N already exists and is checked out, git refuses
# to fetch into it (causes "refusing to fetch into branch")
# Adding refs/pull/*/head to the fetch refspec solves issue 1, and we avoid
# creating local branches to prevent issue 2.
- name: Configure git for PR ref access
run: |
git config --add remote.origin.fetch '+refs/pull/*/head:refs/remotes/origin/pull/*/head'
# Invoke Claude to perform an automated PR review with progress tracking
- name: Run Claude Code Review
id: claude-review
uses: anthropics/claude-code-action@v1
with:
anthropic_api_key: ${{ secrets.ANTHROPIC_API_KEY }}
github_token: ${{ secrets.GITHUB_TOKEN }}
# Enable progress tracking and show full Claude output in logs
track_progress: true
# Custom review instructions passed to Claude
prompt: |
REPO: ${{ github.repository }}
Perform a comprehensive code review with the following focus areas:
1. **Code Quality**
- Clean code principles and best practices
- Proper error handling and edge cases
- Code readability and maintainability
2. **Security**
- Check for potential security vulnerabilities
- Validate input sanitization
- Review authentication/authorization logic
3. **Performance**
- Identify potential performance bottlenecks
- Review database queries for efficiency
- Check for memory leaks or resource issues
4. **Testing**
- Verify adequate test coverage
- Review test quality and edge cases
- Check for missing test scenarios
5. **Documentation**
- Ensure code is properly documented
- Verify README updates for new features
- Check API documentation accuracy
Provide detailed feedback using inline comments for specific issues.
Use top-level comments for general observations or praise.
# Restrict tools that Claude can use during the review
claude_args: |
--allowedTools "mcp__github_inline_comment__create_inline_comment,Bash(gh pr comment:*),Bash(gh pr diff:*),Bash(gh pr view:*)"