AgentSkillsCN

fix-pr-comments

获取未解决的 PR 评论并修复其中的问题

SKILL.md
--- frontmatter
name: fix-pr-comments
description: Fetch unresolved PR comments and fix the issues
allowed-tools: Bash, Read, Edit, Grep, Glob, AskUserQuestion

Fix PR Comments

Fetch unresolved review comments from the current PR and fix them interactively.

Instructions

Step 1: Get PR Information

Run the following to get the current PR's owner, repo, and number:

bash
gh pr view --json number,headRepositoryOwner,headRepository -q '{owner: .headRepositoryOwner.login, repo: .headRepository.name, number: .number}'

If this fails, the current branch likely doesn't have an open PR. Inform the user and stop.

Step 2: Fetch Unresolved Review Threads

Use the GitHub GraphQL API to get all unresolved review threads:

bash
gh api graphql -f query='
query($owner: String!, $repo: String!, $pr: Int!) {
  repository(owner: $owner, name: $repo) {
    pullRequest(number: $pr) {
      reviewThreads(first: 100) {
        nodes {
          isResolved
          comments(first: 10) {
            nodes {
              body
              path
              line
              author { login }
            }
          }
        }
      }
    }
  }
}
' -f owner=OWNER -f repo=REPO -F pr=NUMBER

Replace OWNER, REPO, and NUMBER with values from Step 1.

Step 3: Filter and Process Comments

From the response:

  1. Filter to threads where isResolved: false
  2. For each thread, get the first comment (the original feedback)
  3. Skip comments that are just questions or discussions (no actionable code change requested)

Step 4: Interactive Fixing

For each actionable unresolved comment:

  1. Present the comment to the user:

    • File path and line number
    • Author
    • Comment body
  2. Ask the user using AskUserQuestion with options:

    • "Fix" - Apply the requested change
    • "Skip" - Move to next comment
    • "Stop" - End processing
  3. If "Fix":

    • Read the relevant file
    • Understand the context around the line
    • Apply the fix using the Edit tool
    • Confirm the fix was applied

Step 5: Output Summary

After processing all comments, output:

code
## PR Comments Fixed

**Fixed:** [count] comments
**Skipped:** [count] comments

### Changes Made:
- [file:line] - [brief description of fix]
- ...

If no unresolved comments were found, output:

code
No unresolved PR comments found.