关于 all-green
all-green 是一项帮助 Agent 将 GitHub 拉取请求整理至可合并状态的技能,按步骤处理审查意见、冲突和检查失败,并核验最终状态。
主要功能
- 01查看 PR 状态与 CI 检查
- 02获取并解决审查讨论
- 03变基处理合并冲突
- 04诊断并修复失败检查
- 05等待检查并核验就绪状态
适用场景
- 01准备分支上的 PR 以供合并
- 02处理尚未解决的审查意见
- 03排查冲突与 CI 检查失败
安装
复制下面的命令,在终端中运行。
$
npx skills add https:/ / github.com/ continuedev/ skills --skill all-green安装后在 Claude Code 中输入/all-green确认已加载。
详细介绍
全绿:让 PR 达到可合并状态
你的目标是解决所有阻碍因素,让此 PR 达到可合并状态:审核评论、合并冲突和失败的检查。
工作流
按顺序执行以下步骤:
1. 确定 PR
首先,确定要处理哪个 PR:
# Get current branch and find associated PR
gh pr view --json number,title,url,headRefName,baseRefName,mergeable,mergeStateStatus,reviewDecision
如果当前分支没有 PR,请告知用户并停止。
2. 检查 PR 状态
全面了解需要处理的事项:
# Check for merge conflicts
gh pr view --json mergeable,mergeStateStatus
# Get CI check status
gh pr checks
3. 获取并处理所有审核讨论串
重要:你必须使用 GraphQL API 获取审核讨论串,并处理每个未解决的讨论串。这不是可选项。跳过此步骤是 PR 无法达到可合并状态的头号原因。
步骤 3a:获取所有审核讨论串(必须执行)
gh api graphql -f query='
{
repository(owner: "{owner}", name: "{repo}") {
pullRequest(number: {pr_number}) {
reviewThreads(first: 100) {
nodes {
id
isResolved
comments(first: 5) {
nodes { body path line author { login } }
}
}
}
}
}
}'
筛选未解决的讨论串:查找 "isResolved": false。如果没有未解决的讨论串,可以跳到步骤 4。否则,你必须逐一处理。
步骤 3b:对每个未解决的讨论串,都执行以下所有操作:
- 阅读评论,了解对方的要求
- 阅读相关代码,查看所提及的文件和行
- 按要求修改(如果不同意,则说明原因)
- 回复讨论串,说明你所做的修改:
gh api graphql -f query=' mutation { addPullRequestReviewThreadReply(input: { pullRequestReviewThreadId: "PRRT_xxx" body: "Fixed in commit abc123" }) { comment { id } } }' - 解决讨论串——这一步必须执行,不要跳过:
gh api graphql -f query=' mutation { resolveReviewThread(input: { threadId: "PRRT_xxx" }) { thread { isResolved } } }'
步骤 3c:确认所有讨论串均已解决(必须执行)
处理完所有讨论串后,重新运行步骤 3a 中的 GraphQL 查询,并确认没有未解决的讨论串。如果仍有未解决的讨论串,请返回并处理。
提示:
- 按文件顺序处理评论,避免行号发生偏移
- 如果评论不清楚,请向用户寻求澄清
- 如果不同意某项建议,请在回复中说明原因,并仍然解决该讨论串
- 务必先回复,再解决讨论串,以便审核者了解采取了哪些措施
- 在回复和解决讨论串之前,先提交并推送修复,这样就能引用提交哈希
4. 解决合并冲突
如果 PR 存在合并冲突:
# Fetch latest changes
git fetch origin
# Get the base branch name from PR
BASE_BRANCH=$(gh pr view --json baseRefName -q .baseRefName)
# Rebase onto the base branch
git rebase origin/$BASE_BRANCH
解决冲突时:
- 仔细阅读两个版本,了解其意图
- 如果两项修改互不影响,则保留两者
- 如果两项修改冲突,则选择正确的版本
- 解决后运行类型检查,以发现问题
# After resolving conflicts
git add <resolved-files>
git rebase --continue
# Verify types still check
npm run tsgo:check
5. 修复失败的检查
对于每项失败的检查:
# Get detailed check failure information
gh pr checks --json name,state,conclusion,detailsUrl
常见修复方法:
类型错误:
npm run tsgo:check # Identify the errors
# Fix each type error in the reported files
Lint 错误:
npm run lint # See lint issues
npm run lint:fix # Auto-fix what's possible
# Manually fix remaining issues
测试失败:
npm test # Run tests to see failures
# Read failing test files and fix the issues
构建失败:
- 检查是否缺少导入
- 检查是否存在语法错误
- 确认已安装所有依赖项
6. 推送并等待检查
完成所有修复后:
# If you rebased, force push is required
git push --force-with-lease
# If you only added commits
git push
然后使用阻塞式监视命令等待检查完成:
# Block until checks finish, exit immediately on first failure
gh pr checks --watch --fail-fast
此命令:
- 阻塞直至所有检查完成(无需轮询,也不会浪费令牌)
- 如果任何检查失败,则立即以状态码 1 退出(快速失败)
- 如果所有检查均通过,则以状态码 0 退出
- 如果检查仍在等待中,则以状态码 8 退出(使用
--watch时不应发生)
7. 处理检查失败
如果 gh pr checks --watch --fail-fast 以失败状态退出:
# See which check failed and get the details URL
gh pr checks --json name,state,conclusion,detailsUrl
# View the failed run logs directly
gh run view <run-id> --log-failed
修复问题、提交、推送,然后再次运行 gh pr checks --watch --fail-fast。
8. 确认已准备好合并
检查通过后:
gh pr view --json mergeable,mergeStateStatus,reviewDecision
重要说明
- 必须处理并解决每个未解决的审核讨论串——这是让 PR 全绿最重要的一步。不要跳过此步骤,也不要将其视为可选项。务必通过后续的 GraphQL 查询确认没有未解决的讨论串。
- 如果分支上可能有其他协作者,请在强制推送前先征求同意
- 经常运行类型检查,及早发现问题
- 按逻辑提交——将相关修复归为一组
- 如果修复后检查仍持续失败,请仔细阅读 CI 日志:
gh run view <run-id> --log-failed
示例会话
# 1. See what we're dealing with
gh pr view --json number,title,mergeable,mergeStateStatus,reviewDecision
gh pr checks
# 2. MANDATORY: Fetch ALL review threads and find unresolved ones
gh api graphql -f query='{
repository(owner: "OWNER", name: "REPO") {
pullRequest(number: PR_NUM) {
reviewThreads(first: 100) {
nodes { id isResolved comments(first: 5) { nodes { body path line author { login } } } }
}
}
}
}'
# 3. Address each unresolved thread: read code, make fix, commit
# 4. Push fixes
git push
# 5. Reply to and resolve EVERY addressed thread
gh api graphql -f query='mutation { addPullRequestReviewThreadReply(input: { pullRequestReviewThreadId: "PRRT_xxx", body: "Fixed in abc123 — added encodeURIComponent" }) { comment { id } } }'
gh api graphql -f query='mutation { resolveReviewThread(input: { threadId: "PRRT_xxx" }) { thread { isResolved } } }'
# 6. VERIFY: Re-fetch threads and confirm zero unresolved remain
# (Re-run the GraphQL query from step 2, filter for isResolved: false)
# 7. If there are merge conflicts, rebase
git fetch origin
git rebase origin/main
# ... resolve conflicts ...
git add .
git rebase --continue
# 8. Fix any failing checks
npm run tsgo:check
npm run lint:fix
npm test
# 9. Push and wait for checks (blocks until complete, fails fast)
git push --force-with-lease
gh pr checks --watch --fail-fast
# 10. If checks failed, fix and repeat. Once green:
gh pr view --json mergeable,mergeStateStatus,reviewDecision
评论
支持 Markdown