AgentSkillsCN

gh-address-comments

通过 gh CLI 进行 GitHub PR 评审操作。添加行内评论,提交评审(批准/拒绝/发表评论)。当您需要添加 PR 评论、提交评审,或管理 GitHub 代码评审时,可使用此技能。

SKILL.md
--- frontmatter
name: gh-address-comments
description: Address review/issue comments on the open GitHub PR for the current branch. Fetches all comments and review threads, summarizes what needs attention, and helps apply fixes. Use when responding to PR feedback, resolving review comments, or when user mentions "address comments" or "fix review feedback".
allowed-tools: Bash(gh:*), Bash(jq:*), Read, Write, Edit

GitHub Address Comments

Fetch and address review comments on the open PR for the current branch using the gh CLI.

Quick Start

bash
# Fetch all comments for current branch's PR
${SKILL_DIR}/scripts/fetch-comments.sh

# Fetch comments for specific PR
${SKILL_DIR}/scripts/fetch-comments.sh 123

Workflow

Step 1: Fetch Comments

Run the fetch script to get all PR comments:

bash
COMMENTS=$(${SKILL_DIR}/scripts/fetch-comments.sh)

Step 2: Summarize and Number

Present a numbered list of actionable items:

  1. Review each review_threads entry (inline comments on specific lines)
  2. Review each conversation_comments entry (general PR comments)
  3. Skip resolved threads (isResolved: true)
  4. Summarize what fix is needed for each

Example summary format:

code
## PR Comments Needing Attention

1. [src/app.ts:42] Missing null check before accessing property
2. [src/utils.ts:15-20] Consider extracting to helper function
3. [General] Add tests for edge cases

Which comments would you like me to address? (e.g., "1,3" or "all")

Step 3: User Selection

Ask which numbered comments to address. Options:

  • Specific numbers: 1,3
  • All: all
  • None: none

Step 4: Apply Fixes

For each selected comment:

  1. Read the relevant file
  2. Apply the requested fix
  3. Mark as addressed in summary

Script Documentation

fetch-comments.sh

Fetches all PR comments using GitHub GraphQL API.

Usage:

bash
${SKILL_DIR}/scripts/fetch-comments.sh [PR_NUMBER]

Output:

json
{
  "pull_request": {
    "number": 123,
    "url": "https://github.com/owner/repo/pull/123",
    "title": "Add new feature",
    "state": "OPEN",
    "owner": "owner",
    "repo": "repo"
  },
  "conversation_comments": [
    {
      "id": "IC_...",
      "body": "Please add tests",
      "author": "reviewer",
      "createdAt": "2024-01-15T10:00:00Z"
    }
  ],
  "reviews": [
    {
      "id": "PRR_...",
      "state": "CHANGES_REQUESTED",
      "body": "Good start, but needs some changes",
      "author": "reviewer",
      "submittedAt": "2024-01-15T10:00:00Z"
    }
  ],
  "review_threads": [
    {
      "id": "PRRT_...",
      "isResolved": false,
      "isOutdated": false,
      "path": "src/app.ts",
      "line": 42,
      "comments": [
        {
          "id": "PRRC_...",
          "body": "Missing null check here",
          "author": "reviewer",
          "createdAt": "2024-01-15T10:00:00Z"
        }
      ]
    }
  ]
}

Error Handling

The script returns JSON errors:

json
{
  "error": true,
  "message": "gh CLI not authenticated. Run 'gh auth login' first.",
  "code": "AUTH_REQUIRED"
}

Error codes:

CodeDescription
GH_NOT_INSTALLEDgh CLI not installed
AUTH_REQUIREDRun gh auth login
JQ_NOT_INSTALLEDjq not installed
NOT_GIT_REPONot in a git repository
NO_PRNo PR found for current branch
API_ERRORGitHub API error

Guidelines

  • Always fetch fresh comments before addressing (PRs update frequently)
  • Skip resolved threads unless user explicitly asks
  • Skip outdated threads (code has changed) unless relevant
  • For inline comments, show the file path and line number
  • Apply fixes one at a time, verifying each works
  • If a comment is unclear, ask for clarification before fixing

Requirements

  • gh CLI installed and authenticated (gh auth login)
  • jq for JSON processing
  • Git repository with GitHub remote
  • Open PR for current branch (or specify PR number)

Related Skills

  • gh-pr-review - Create reviews (outbound)
  • This skill - Address reviews (inbound)

Adapted from openai/skills/gh-address-comments