pr-comments
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseAddress PR Comments
处理PR评论
Pull all review comments from the current GitHub pull request and address each one by making the necessary code changes.
从当前GitHub拉取请求中提取所有评审评论,并通过做出必要的代码修改来处理每一条评论。
Step 1: Identify the PR
步骤1:识别PR
If the user provided a PR number as , use that. Otherwise, detect the PR for the current branch:
$ARGUMENTSgh pr view --json number,title,url,headRefNameIf no PR is found, inform the user and stop.
如果用户提供了PR编号作为,则使用该编号。否则,检测当前分支对应的PR:
$ARGUMENTSgh pr view --json number,title,url,headRefName如果未找到PR,通知用户并停止操作。
Step 2: Fetch all review comments
步骤2:获取所有评审评论
Get all review comments (file-level comments, not general PR comments) using:
gh api repos/{owner}/{repo}/pulls/{number}/comments --paginate --jq '.[] | {id, path, line, original_line, side, body, diff_hunk, subject_type, user: .user.login, created_at, in_reply_to_id}'Also fetch review threads via GraphQL to understand resolved vs unresolved status (note: does NOT support ):
gh pr view --jsonreviewThreadsgh api graphql -f query='
{
repository(owner: "{owner}", name: "{repo}") {
pullRequest(number: {number}) {
reviewThreads(first: 100) {
nodes {
id
isResolved
comments(first: 10) {
nodes {
databaseId
path
originalStartLine
startLine
body
author { login }
}
}
}
}
}
}
}'Filter the results to only unresolved threads (). The field on each thread node is the GraphQL node ID needed to resolve the thread later.
isResolved == falseid使用以下命令获取所有评审评论(文件级评论,而非通用PR评论):
gh api repos/{owner}/{repo}/pulls/{number}/comments --paginate --jq '.[] | {id, path, line, original_line, side, body, diff_hunk, subject_type, user: .user.login, created_at, in_reply_to_id}'同时通过GraphQL获取评审线程,以了解已解决和未解决状态(注意: 不支持):
gh pr view --jsonreviewThreadsgh api graphql -f query='
{
repository(owner: "{owner}", name: "{repo}") {
pullRequest(number: {number}) {
reviewThreads(first: 100) {
nodes {
id
isResolved
comments(first: 10) {
nodes {
databaseId
path
originalStartLine
startLine
body
author { login }
}
}
}
}
}
}
}'过滤结果,仅保留未解决的线程()。每个线程节点的字段是后续解决线程所需的GraphQL节点ID。
isResolved == falseidStep 3: Filter and organize
步骤3:筛选与整理
- Only address unresolved comment threads - skip any threads that are already resolved.
- Skip reply comments (those with set) - only process top-level comments in each thread.
in_reply_to_id - Group comments by file path for efficient processing.
- Present a summary to the user showing each comment with:
- File path and line number
- Who wrote the comment
- The comment body
- The relevant code context (from diff_hunk)
- 仅处理未解决的评论线程 - 跳过已解决的线程。
- 跳过回复评论(带有的评论)- 仅处理每个线程中的顶级评论。
in_reply_to_id - 按文件路径分组评论以提高处理效率。
- 向用户展示摘要,每条评论包含:
- 文件路径和行号
- 评论作者
- 评论内容
- 相关代码上下文(来自diff_hunk)
Step 4: Address each comment
步骤4:处理每条评论
For each unresolved comment:
- Read the relevant file to understand the full context around the commented line.
- Analyze the comment to determine what change is being requested.
- Make the code change using the Edit tool.
- Resolve the comment thread on GitHub using the GraphQL API:
To get the thread node ID, include
gh api graphql -f query='mutation { resolveReviewThread(input: {threadId: "<thread_node_id>"}) { thread { isResolved } } }'(the GraphQL node ID) when fetching review threads in Step 2.id - Briefly explain what you changed and why.
If a comment is unclear or requires a design decision, flag it to the user instead of guessing. Do NOT resolve these threads.
对于每条未解决的评论:
- 读取相关文件,了解评论行周围的完整上下文。
- 分析评论,确定所需的修改内容。
- 使用编辑工具进行代码修改。
- 通过GraphQL API在GitHub上解决评论线程:
要获取线程节点ID,在步骤2获取评审线程时需包含
gh api graphql -f query='mutation { resolveReviewThread(input: {threadId: "<thread_node_id>"}) { thread { isResolved } } }'(GraphQL节点ID)。id - 简要说明所做的修改及原因。
如果评论内容不明确或需要进行设计决策,请标记给用户,不要自行猜测。不要解决这些线程。
Step 5: Summary
步骤5:总结
After addressing all comments, provide a summary:
- List each comment and what was done to address it
- Note any comments that were skipped or need human input
- Remind the user to review the changes before committing
处理完所有评论后,提供总结:
- 列出每条评论及对应的处理操作
- 记录跳过或需要人工介入的评论
- 提醒用户在提交前审查修改内容