Fetch PR comments using the gh CLI

The "fix this with copilot" button on GitHub is great, but when you're already working on a branch locally sometimes you want to pass the review feedback to your agent directly.

If you use the gh CLI, you can install this by running gh extension install mheap/gh-pr-comments.

Once it's installed, run gh pr-comments <PR number> | pbcopy to get all of the comments ready to paste in to your agent.

Here's what it does under the hood:

bash
#!/usr/bin/env bash
set -euo pipefail
if (( $# < 1 || $# > 2 )) || [[ ! ${1:-} =~ ^[0-9]+$ ]]; then
echo "Usage: gh pr-comments <PR number> [owner/repo]" >&2
exit 1
fi
pr="$1"
repo="${2:-}"
if [[ -z "$repo" ]]; then
repo="$(gh repo view --json nameWithOwner --jq '.nameWithOwner')"
fi
gh api --paginate "repos/$repo/pulls/$pr/comments" | jq -c '.[] | {path, line, body}'