Address comments

From drn/dots · View interactive version

Address comments is an AI agent skill from the GitHub repository drn/dots. Walk every unresolved review thread on a PR, triage each one, reply with a rationale of whether or not the comment will be acted upon, make the code change if warranted, and mark the thread resolved. Use when the user asks to address only the open PR comments without re-running CI, respond to review

How to use this skill

Skill file

Arguments

Context

Your task

Walk every unresolved review thread on the target PR. For each thread: read the comment in context, decide whether to act on it, make the code change if warranted, post a reply explaining the rationale, then resolve the thread. End with a clean PR (zero unresolved threads) and a one-paragraph summary of what was done.

This skill does not push the branch into CI babysitting or merge it — use /pr or /merge for that. The focused job here is _comment hygiene_.

Step 1: Identify the PR

First, derive the upstream repo slug. Prefer the upstream remote if it exists, otherwise origin. The rules below all need it.

REPO_SLUG=$(git remote get-url upstream 2>/dev/null | sed -E 's|.*[:/]([^/]+/[^/.]+)(\.git)?$|\1|')
[ -z "$REPO_SLUG" ] && REPO_SLUG=$(git remote get-url origin | sed -E 's|.*[:/]([^/]+/[^/.]+)(\.git)?$|\1|')

Then determine the target PR by applying these rules in order:

Find the PR number with gh pr list --repo <slug> --head '<branch>' --state open --json number,url.

Cross-fork PRs. If gh pr list --head '<branch>' returns zero results AND an upstream remote exists, the branch may live on a fork. Resolve the fork owner from the origin remote and retry with the qualified --head '<fork-owner>:<branch>':

FORK_OWNER=$(git remote get-url origin | sed -E 's|.*[:/]([^/]+)/[^/.]+(\.git)?$|\1|')
gh pr list --repo "$REPO_SLUG" --head "$FORK_OWNER:<branch>" --state open --json number,url

If no open PR is found after both attempts, stop and tell the user: No open PR found for <branch>. Open one with /pr first. Do not try to open one — that is /pr's job.

Step 2: Fetch every unresolved review thread

Use the GraphQL API to get all threads in one shot — REST does not expose isResolved. The first: 100 page size is GitHub's connection maximum; pagination handles PRs larger than that (see below). The first: 50 comment window per thread is generous enough for the idempotency-guard scan in Step 3(b) on normal threads. Two ID fields matter here and they are easy to confuse:

Do not swap them — the URL in Step 3(e) takes the comment's databaseId, not the thread's id.

gh api graphql -F owner=<owner> -F repo=<repo> -F number=<n> -f query='
  query($owner: String!, $repo: String!, $number: Int!, $after: String) {
    repository(owner: $owner, name: $repo) {
      pullRequest(number: $number) {
        reviewThreads(first: 100, after: $after) {
          pageInfo { hasNextPage endCursor }
          nodes {
            id
            isResolved
            isOutdated
            path
            line
            comments(first: 50) {
              nodes {
                databaseId
                body
                author { login }
                path
                line
                originalLine
                diffHunk
              }
            }
          }
        }
      }
    }
  }'

Filter to threads where isResolved == false. If there are zero, stop and report: No unresolved review threads on PR #<n>.

Pagination. If pageInfo.hasNextPage is true, the PR has more than 100 review threads. Re-issue the same query with -F after=<endCursor> (the $after variable is already declared in the signature above) and concatenate the pages before continuing. PRs with very large bot-comment volumes (e.g. a CodeRabbit pass on a sweeping refactor) hit this case; do not silently process only the first page.

Step 3: Triage and act on each thread

For each unresolved thread, work through it in this order. Do not parallelize — review threads can suggest conflicting edits to the same lines, and you need to apply them sequentially with the latest file state in mind.

(a) Read the code in context. Open path and read the function or block that contains line — not just the diff hunk. Bot comments often miss surrounding context that changes the verdict.

(b) Identify the author and decide whether to skip.

Capture the viewer login once at the start of Step 3 with gh api user -q .login (call it VIEWER). Then run these two checks in order — the first comment's author and the remaining comments are checked separately and produce different outcomes:

  1. Thread-author check. Look at the first comment in comments.nodes[]. If comments.nodes[0].author.login == VIEWER, this is a thread the agent itself authored. Skip the thread entirely — no reply, no resolve, do not run check 2. (Caveat: on a fork PR where the maintainer and the contributor share a GitHub user, this can over-skip; if the agent is reviewing its own PR, that risk is acceptable.)
  2. Idempotency check. Only reach this check if check 1 did not fire. Scan comments.nodes[1..] (every comment after the first) for any whose author.login == VIEWER. If one exists, the agent already replied on a previous run and the resolve mutation was the step that failed — follow the idempotency path below. If no VIEWER comment appears past index 0, this is a fresh thread — fall through to (c)/(d)/(e)/(f) as normal.

Bot context (informational): bot usernames typically end in [bot] (e.g. coderabbitai[bot], qltysh[bot], github-actions[bot], copilot-pull-request-review[bot]). Bots produce a high false-positive rate — evaluate each suggestion on its merits, do not blindly apply.

Idempotency path (only when check 2 fired):

(c) Classify. Pick exactly one bucket:

Heuristics for bots:

(d) If (1), make the code change. Edit the file. Keep the change minimal — fix the specific issue, do not refactor surrounding code. If multiple threads point at the same code, batch the related edits before replying so the reply can reference the final state.

(e) Reply with rationale. Post the reply _before_ resolving so there is always an audit trail. The reply must state the verdict and the reasoning in one or two sentences. Do not write "Thanks for the feedback" or other filler.

Reply templates (use these structures, then fill in every <…> placeholder before posting):

If you cannot fill in a placeholder (e.g. the fix touched several files and you cannot name one path:line, or the rationale needs context you do not have), stop and surface the thread to the user in the Step 5 summary instead of posting raw <…> placeholder text. Posted replies are visible to reviewers — a literal <one line describing the change> reply is worse than no reply. This applies to every reply this skill posts, including the outdated-thread template referenced in the Notes section below.

Post the reply with the REST endpoint (no native gh command exists, but gh api works). The path uses <n> (pull number) and the comment's databaseId — not the thread's id:

gh api -X POST \
  "/repos/<owner>/<repo>/pulls/<n>/comments/<first_comment_databaseId>/replies" \
  -f body="<reply text>"

(f) Resolve the thread via GraphQL mutation:

gh api graphql -F threadId=<thread node id> -f query='
  mutation($threadId: ID!) {
    resolveReviewThread(input: {threadId: $threadId}) {
      thread { isResolved }
    }
  }'

Track a running tally as you go: fixed, left, acknowledged.

Step 4: Commit and push code changes

If any files changed during Step 3:

  1. git status --short to confirm only the expected files were touched.
  2. Stage the specific files you edited with git add <path1> <path2> ... — list paths explicitly, do not use git add -A, git add ., git commit -a, or git commit --all. The agent may have unrelated dirty state in the working tree and the policy is to ship only the comment-driven edits.
  3. Commit with a message scaled to the change set:
  1. git push (use git push -u origin HEAD if no upstream is set).

If no files changed, skip this step entirely. Do not create an empty commit.

Step 5: Report

Print a tight summary the user can scan:

PR: <url>
Addressed N threads — F fixed, L left as-is, A acknowledged.
<one-line per fix referencing path:line, if F > 0>

If anything blocked progress (a thread you could not classify, a file you could not edit, a push that was rejected), surface it explicitly instead of silently finishing.

Notes and edge cases

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.