Skip to content

Instantly share code, notes, and snippets.

@locofocos
Created January 11, 2026 04:05
Show Gist options
  • Select an option

  • Save locofocos/90ebbce36c6e4bd03b3e6710acc5766e to your computer and use it in GitHub Desktop.

Select an option

Save locofocos/90ebbce36c6e4bd03b3e6710acc5766e to your computer and use it in GitHub Desktop.
Cursor command to allow fetching Github PR discussions. Surround the URL param with backticks.

fetch-pr-thread

Fetch a GitHub PR discussion thread (parent + replies) given a discussion_r... URL.

Usage

Run this command in a shell (or adapt it to your shell command runner in Cursor), then paste a URL like:

  • https://github.com/uprightlabs/lister/pull/10767#discussion_r2611606010

It will print each comment in the thread as author: followed by the body, separated by ---.

#!/usr/bin/env bash

set -euo pipefail

if [ "$#" -lt 1 ]; then
  echo "Usage: fetch-pr-thread <github_pr_discussion_url>" >&2
  exit 1
fi

URL="$1"

# Extract owner, repo, PR number, and parent discussion comment id
owner=$(echo "$URL" | sed -n 's#https://github.com/\([^/]*\)/.*#\1#p')
repo=$(echo "$URL" | sed -n 's#https://github.com/[^/]*/\([^/]*\)/.*#\1#p')
pr=$(echo   "$URL" | sed -n 's#.*/pull/\([0-9]*\).*#\1#p')
parent=$(echo "$URL" | sed -n 's/.*discussion_r\([0-9]*\).*/\1/p')

if [ -z "$owner" ] || [ -z "$repo" ] || [ -z "$pr" ] || [ -z "$parent" ]; then
  echo "Failed to parse URL: $URL" >&2
  echo "Expected format: https://github.com/<owner>/<repo>/pull/<pr>#discussion_r<commentId>" >&2
  exit 1
fi

# Fetch parent comment + all replies in the thread
gh api "repos/$owner/$repo/pulls/$pr/comments" --paginate \
  --jq ".[] |
    select(.id == $parent or .in_reply_to_id == $parent) |
    \"\(.user.login):\\n\(.body)\\n---\""

This command will be available in chat with /fetch-pr-thread.

When running gh api (either directly or via this script), make sure it runs outside the sandbox so gh can use the macOS keychain. Otherwise you may see TLS cert errors. In tool calls, set required_permissions: ["all"] when running gh commands.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment