Review pull request changes between branches or GitHub PRs with senior developer standards
Review PR changes with senior Java standards, focusing on Clean Code and avoiding over-design. Use for GitHub PRs (by number) or local branch comparisons to check commit quality, test coverage, and breaking changes.
/plugin marketplace add xinqilin/claude-dev-toolkit-marketplace/plugin install bill-code-reviewer@bill-lin-dev-toolkit[compare-branch-or-pr-number] [base-branch]sonnetReview pull request changes with senior Java developer standards, focusing on Clean Code and avoiding over-design.
Supports two modes:
gh CLI)git diff)Review the changes in a pull request, not just static code. Focus on:
This command accepts two optional parameters with automatic detection:
123 or #123): Review GitHub PR using gh CLIfeature-auth): Review local branch using git diffmasterExamples:
# Review GitHub PR #123 (gh mode)
/review-pr 123
/review-pr #123
# Review current branch against master (git diff mode)
/review-pr
# Review feature-branch against master (git diff mode)
/review-pr feature-branch
# Review feature-branch against develop (git diff mode)
/review-pr feature-branch develop
Automatically detect whether to use GitHub PR mode or branch comparison mode.
# Get first parameter
INPUT=${1:-""}
# Detect parameter type
if [[ -z "$INPUT" ]]; then
# Empty parameter: use current branch vs master (git diff mode)
MODE="git_diff"
CURRENT_BRANCH=$(git rev-parse --abbrev-ref HEAD 2>/dev/null)
COMPARE=$CURRENT_BRANCH
BASE=${2:-master}
elif [[ "$INPUT" =~ ^#?[0-9]+$ ]]; then
# Pure number (with optional # prefix): PR number (gh mode)
MODE="gh_pr"
PR_NUMBER="${INPUT#\#}" # Remove # prefix if present
else
# Other: branch name (git diff mode)
MODE="git_diff"
COMPARE=$INPUT
BASE=${2:-master}
fi
MODE="gh_pr")This mode uses GitHub CLI (gh) to review a PR by PR number.
if [[ "$MODE" == "gh_pr" ]]; then
# Check if gh is installed
if ! command -v gh &> /dev/null; then
echo "錯誤:GitHub CLI (gh) 未安裝"
echo ""
echo "請執行以下指令安裝:"
echo " brew install gh"
echo ""
echo "或參考:https://cli.github.com/"
exit 1
fi
# Check if gh is authenticated
if ! gh auth status &> /dev/null; then
echo "錯誤:GitHub CLI 尚未認證"
echo ""
echo "請執行以下指令進行認證:"
echo " gh auth login"
echo ""
exit 1
fi
fi
if [[ "$MODE" == "gh_pr" ]]; then
# Get PR metadata using JSON output
PR_JSON=$(gh pr view "$PR_NUMBER" --json \
number,title,body,state,author,\
baseRefName,headRefName,\
additions,deletions,changedFiles,\
statusCheckRollup,latestReviews,\
createdAt,updatedAt 2>&1)
# Check if command succeeded
if [[ $? -ne 0 ]]; then
echo "錯誤:無法取得 PR #$PR_NUMBER 的資訊"
echo ""
echo "$PR_JSON"
echo ""
echo "請確認:"
echo "1. PR 編號是否正確"
echo "2. 你是否有權限存取此 repository"
echo "3. 是否在正確的 git repository 中"
exit 1
fi
# Parse JSON (requires jq)
# Check if jq is available
if ! command -v jq &> /dev/null; then
echo "警告:jq 未安裝,將使用簡化的 JSON 解析"
echo "建議安裝 jq 以獲得更好的體驗:brew install jq"
# Use simplified parsing if jq is not available
PR_TITLE=$(echo "$PR_JSON" | grep -o '"title":"[^"]*"' | cut -d'"' -f4)
PR_AUTHOR=$(echo "$PR_JSON" | grep -o '"login":"[^"]*"' | head -1 | cut -d'"' -f4)
PR_STATE=$(echo "$PR_JSON" | grep -o '"state":"[^"]*"' | cut -d'"' -f4)
else
# Use jq for reliable JSON parsing
PR_TITLE=$(echo "$PR_JSON" | jq -r '.title')
PR_AUTHOR=$(echo "$PR_JSON" | jq -r '.author.login')
PR_STATE=$(echo "$PR_JSON" | jq -r '.state')
BASE_BRANCH=$(echo "$PR_JSON" | jq -r '.baseRefName')
HEAD_BRANCH=$(echo "$PR_JSON" | jq -r '.headRefName')
ADDITIONS=$(echo "$PR_JSON" | jq -r '.additions')
DELETIONS=$(echo "$PR_JSON" | jq -r '.deletions')
CHANGED_FILES=$(echo "$PR_JSON" | jq -r '.changedFiles')
fi
# Get diff
PR_DIFF=$(gh pr diff "$PR_NUMBER" --patch 2>&1)
# Get changed files list
CHANGED_FILES_LIST=$(gh pr diff "$PR_NUMBER" --name-only 2>&1)
# Get commits
PR_COMMITS=$(gh pr view "$PR_NUMBER" --json commits \
--jq '.commits[] | "\(.oid[0:7]) \(.messageHeadline)"' 2>&1)
fi
MODE="git_diff")This mode uses standard git diff to compare local branches.
First, verify we're in a git repository:
if [[ "$MODE" == "git_diff" ]]; then
git rev-parse --git-dir 2>/dev/null
if [[ $? -ne 0 ]]; then
echo "錯誤:此指令必須在 git repository 中執行"
exit 1
fi
fi
if [[ "$MODE" == "git_diff" ]]; then
# Get current branch
CURRENT_BRANCH=$(git rev-parse --abbrev-ref HEAD)
# Compare and base branches were already set in Step 0
# COMPARE=${1:-$CURRENT_BRANCH}
# BASE=${2:-master}
fi
if [[ "$MODE" == "git_diff" ]]; then
# Verify compare branch exists
if ! git rev-parse --verify "$COMPARE" >/dev/null 2>&1; then
echo "錯誤:Branch '$COMPARE' 不存在"
echo ""
echo "可用的 branches:"
git branch -a
echo ""
# Fallback: Try to find corresponding PR on GitHub
echo "嘗試在 GitHub 上查找對應的 PR..."
if command -v gh &> /dev/null && gh auth status &> /dev/null; then
PR_INFO=$(gh pr list --head "$COMPARE" --json number,title --limit 1 2>/dev/null)
if [[ -n "$PR_INFO" ]] && command -v jq &> /dev/null; then
PR_NUM=$(echo "$PR_INFO" | jq -r '.[0].number')
PR_TITLE=$(echo "$PR_INFO" | jq -r '.[0].title')
if [[ "$PR_NUM" != "null" ]]; then
echo ""
echo "✓ 找到對應的 PR #$PR_NUM: $PR_TITLE"
echo ""
echo "建議使用以下指令審查:"
echo " /review-pr $PR_NUM"
echo ""
fi
fi
fi
exit 1
fi
# Verify base branch exists
if ! git rev-parse --verify "$BASE" >/dev/null 2>&1; then
echo "錯誤:Branch '$BASE' 不存在"
echo ""
echo "可用的 branches:"
git branch -a
exit 1
fi
fi
if [[ "$MODE" == "git_diff" ]]; then
# Get changed files with status
git diff "$BASE..$COMPARE" --name-status
# Get diff statistics
git diff "$BASE..$COMPARE" --stat
# Get commit history
git log "$BASE..$COMPARE" --oneline --no-merges
# Get full diff (for analysis)
git diff "$BASE..$COMPARE"
fi
if [[ "$MODE" == "git_diff" ]]; then
DIFF_OUTPUT=$(git diff "$BASE..$COMPARE")
if [[ -z "$DIFF_OUTPUT" ]]; then
echo "沒有發現任何差異"
echo ""
echo "$COMPARE 和 $BASE 兩個 branch 的程式碼相同"
exit 0
fi
fi
From git diff --name-status, categorize files:
Focus primarily on .java files. Mention other file types (.xml, .yml, .properties) briefly.
For each modified .java file:
Review commit messages and commit structure:
IMPORTANT: Reuse the review principles from code-review.md. Do NOT repeat the full checklist here.
For each changed code block, check:
Refer to /code-review command's detailed guidelines for these areas.
These checks are unique to PR review (not in regular code review):
Look for:
OrderService.java → should have OrderServiceTest.javaCheck if changes might break existing functionality:
# Search for debug code
git diff "$BASE..$COMPARE" | grep -E "System.out.println|TODO|FIXME|XXX"
System.out.println statements?IMPORTANT: All output must be in Traditional Chinese (繁體中文)
PR 資訊 (僅 gh mode):
變更統計:
CI/CD 檢查 (僅 gh mode):
# Parse CI status from PR JSON
if [[ "$MODE" == "gh_pr" ]] && command -v jq &> /dev/null; then
CI_CHECKS=$(echo "$PR_JSON" | jq -r '.statusCheckRollup[]? |
"\(.name): \(.conclusion // .status)"' 2>/dev/null)
if [[ -n "$CI_CHECKS" ]]; then
echo "**CI/CD 檢查**:"
while IFS= read -r check; do
if [[ -z "$check" ]]; then continue; fi
CHECK_NAME=$(echo "$check" | cut -d: -f1)
CHECK_STATUS=$(echo "$check" | cut -d: -f2 | xargs)
case "$CHECK_STATUS" in
SUCCESS) echo "- ✅ $CHECK_NAME (passing)" ;;
FAILURE) echo "- ❌ $CHECK_NAME (failing)" ;;
PENDING|IN_PROGRESS|QUEUED) echo "- ⏳ $CHECK_NAME (pending)" ;;
SKIPPED) echo "- ⊘ $CHECK_NAME (skipped)" ;;
*) echo "- ⚠️ $CHECK_NAME ($CHECK_STATUS)" ;;
esac
done <<< "$CI_CHECKS"
else
echo "**CI/CD 檢查**: 無檢查或資訊不可用"
fi
fi
Commit 數量: [total commits]
Commit 品質評估: 優秀 / 良好 / 需改進
| 檔案 | 評估 | 說明 |
|---|---|---|
| [filename] | [優秀/良好/需改進] | [brief assessment] |
| 問題 | 位置 | 影響 | 修正方式 |
|---|---|---|---|
| [issue description] | [file:line] | [impact] | [fix suggestion] |
| 問題 | 位置 | 影響 | 修正方式 |
|---|---|---|---|
| [issue description] | [file:line] | [impact] | [fix suggestion] |
| 檔案 | 說明 |
|---|---|
| [filename] | [reason for deletion assessment] |
範例:
或
整體評價: 優秀 / 良好 / 需改進 / 不建議合併
優點:
主要風險:
建議合併時機: [建議何時可以合併,或需要什麼條件]
Handle these scenarios gracefully:
Branch doesn't exist:
gh pr list --headNo differences between branches:
Not in git repository:
Merge conflicts exist:
gh CLI not installed:
brew install ghgh CLI not authenticated:
gh auth loginPR doesn't exist:
jq not installed (warning, not error):
brew install jqNetwork issues:
Remember:
/code-reviewThis command (/review-pr) focuses on:
The core code quality review still follows the principles in /code-review:
Don't duplicate the full checklist - refer to /code-review for detailed coding standards.