关于 gerrit
Gerrit 技能通过 git-review 支持代码审查,并用 Python 包装器将查询和查看结果格式化为 Markdown。它将读取操作与提交、评审或放弃更改等操作区分开来。
主要功能
- 01集成 Gerrit 代码审查
- 02查询和查看结果转为 Markdown
- 03通过 git-review 和 SSH 执行动作
- 04提供仓库配置说明
- 05提供身份验证说明
适用场景
- 01查询或查看 Gerrit 评审信息
- 02提交或放弃一项更改
- 03为 git-review 配置仓库
安装
复制下面的命令,在终端中运行。
npx skills add https:/ / github.com/ odyssey4me/ agent-skills --skill gerrit安装后在 Claude Code 中输入/gerrit确认已加载。
包含的文件
除 SKILL.md 外,安装时一起下载的参考资料和脚本。
references/advanced-usage.mdcommon-workflows.mdpermissions.mdtroubleshooting.mdscripts/gerrit.py详细介绍
Gerrit 技能
此技能使用 git-review 集成 Gerrit 代码审查,并通过 Python 封装程序为读取/查看操作提供 Markdown 格式的查询输出。执行操作的命令(提交、审查、放弃)应直接使用 git-review 或 SSH 命令。
网络访问
Gerrit 命令需要通过出站 HTTPS 访问已配置的 Gerrit REST API。Git 获取/推送和 git-review 需要通过 HTTPS 或 SSH 访问已配置的审查和仓库主机。远程操作需要出站网络访问。如果 Agent 环境对此有限制,请在执行第一个远程命令前,通过该环境的审批或网络控制获取访问权限,并重复使用已授予的授权。本地帮助和文件处理不需要网络访问。技能说明不会授予网络权限。遇到 DNS、连接和超时故障时,请将其报告为网络错误;不要通过重置凭据来解决。如果已获批准的访问仍然失败,请停止操作并报告。身份验证和权限错误需要用户处理。
解析脚本路径
示例中的 SKILL_DIR 是当前加载的 SKILL.md 所在目录。
运行命令前,请将其设为该目录的绝对路径;不要假定 Agent
会设置此 Shell 变量。如果脚本路径包含空格,请将其加引号。
前置条件
安装 git-review:pip install git-review — 文档
身份验证
git-review 使用 SSH 与 Gerrit 服务进行身份验证。
# Configure Gerrit username (if different from local user)
git config --global gitreview.username yourgerrituser
# Test SSH connection
ssh -p 29418 [email protected] gerrit version
# Add SSH key to Gerrit
# 1. Generate SSH key if needed: ssh-keygen -t ed25519
# 2. Copy public key: cat ~/.ssh/id_ed25519.pub
# 3. Add to Gerrit: Settings > SSH Keys
Gerrit 支持多种身份验证方式:
- SSH(推荐):git-review 的所有操作均使用此方式
- HTTP/HTTPS:用于 Web UI 和 REST API 访问(在 Settings > HTTP Password 中设置密码)
详情请参阅 Gerrit 身份验证。
初始设置
配置仓库
# One-time setup for a repository
git review -s
# Or manually create .gitreview file in repository root
cat > .gitreview <<EOF
[gerrit]
host=review.example.com
port=29418
project=myproject
defaultbranch=main
EOF
详情请参阅安装指南。
脚本用法
封装脚本(scripts/gerrit.py)使用 Gerrit SSH 查询命令,并将输出格式化为 Markdown。连接详情从 .gitreview 中读取,或通过 --host/--port/--username 标志指定。各命令的读/写分类请参阅 permissions.md。
# Check Gerrit SSH access
$SKILL_DIR/scripts/gerrit.py check
# Changes
$SKILL_DIR/scripts/gerrit.py changes list
$SKILL_DIR/scripts/gerrit.py changes view 12345
$SKILL_DIR/scripts/gerrit.py changes diff 12345
$SKILL_DIR/scripts/gerrit.py changes diff 12345 --patchset 3
$SKILL_DIR/scripts/gerrit.py changes search "status:open project:myproject"
# Projects
$SKILL_DIR/scripts/gerrit.py projects list
所有列表命令均支持 --limit N(默认值为 30)。
全局连接选项:--host、--port(默认值为 29418)、--username。
命令(直接使用 git-review)
执行操作的命令请直接使用 git-review 或 SSH 命令:
提交更改
git review # Submit current branch for review
git review -t topic-name # Submit with topic
git review -f # Submit and close local branch
git review --reviewers user1,user2 # Add reviewers
git review -n # Dry-run (show what would be done)
完整参考:git-review 用法
下载更改
git review -d 12345 # Download change 12345
git review -d 12345,3 # Download patchset 3 of change 12345
git review -x 12345 # Cherry-pick change (no branch)
git review -m 12345 # Compare local changes to remote
下载操作会创建一个名为 review/username/topic 的本地分支。
更新更改
# Make changes to downloaded review
git commit --amend
git review # Upload new patchset
# Update to latest patchset
git review -d 12345 # Re-download updates the branch
高级选项
git review -R # Don't rebase (submit as-is)
git review -D # Draft mode (WIP changes)
git review --no-cache # Skip local cache
git review -v # Verbose output
git review --track # Track remote branch
配置
仓库级设置
文件:.gitreview(仓库根目录)
[gerrit]
host=review.example.com
port=29418
project=myproject/subproject
defaultbranch=main
defaultremote=origin
全局设置
# Set Gerrit username
git config --global gitreview.username myuser
# Set default remote
git config --global gitreview.remote gerrit
# Configure scheme (ssh/http/https)
git config --global gitreview.scheme ssh
配置存储在 ~/.gitconfig 中
示例
日常工作流
# Start work on new feature
git checkout -b feature-branch
# ... make changes ...
git commit -m "Add new feature"
# Submit for review
git review -t feature-topic
# Verify submission
$SKILL_DIR/scripts/gerrit.py changes list # confirm change appears
# Address review comments
# ... make changes ...
git commit --amend
git review
# Verify new patchset uploaded
$SKILL_DIR/scripts/gerrit.py changes view <change-number>
审查他人的更改
# Download change for review
git review -d 12345
# Verify download
$SKILL_DIR/scripts/gerrit.py changes view 12345
# Test the change
# ... run tests, verify code ...
# Return to main branch
git checkout main
git branch -D review/user/topic
使用主题
# Submit with topic
git review -t authentication-refactor
# Verify submission
$SKILL_DIR/scripts/gerrit.py changes list
# All related changes will be grouped under this topic
git commit -m "Part 2: Update tests"
git review -t authentication-refactor
更多示例请参阅 common-workflows.md。
高级用法
有关 SSH 命令、JSON 输出和多服务器配置,请参阅 advanced-usage.md。
模型指南
此技能封装了官方 CLI。快速、轻量的模型即可胜任。
故障排除
常见问题及解决方法请参阅 troubleshooting.md。
官方文档
- git-review 手册:https://docs.opendev.org/opendev/git-review/latest/
- git-review 仓库:https://opendev.org/opendev/git-review
- Gerrit 文档:https://gerrit-review.googlesource.com/Documentation/
- Gerrit SSH 命令:https://gerrit-review.googlesource.com/Documentation/cmd-index.html