Using GitHub API with gh CLI

Retrieve inline PR review comments and thread status via GitHub REST and GraphQL APIs.

Updated Aug 10, 2021
One-click install
npx skills add https://github.com/johnnymo87/dotfiles --skill using-github-api-with-gh-cli
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: Using GitHub API with gh CLI
Source: https://github.com/johnnymo87/dotfiles/tree/main/.claude/skills/using-github-api-with-gh
Command: npx skills add https://github.com/johnnymo87/dotfiles --skill using-github-api-with-gh-cli

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This Skill enables programmatic access to GitHub REST and GraphQL APIs using gh api to fetch inline review comments, thread status, and other data not exposed by standard gh pr view commands.

Core Features & Use Cases

  • Access inline PR review comments
  • Get review thread status (resolved/unresolved)
  • REST API via gh api
  • GraphQL API via gh api
  • Extract owner/repo/PR number from URLs
  • Filter and query PR review data

Quick Start

Use gh api to fetch data, for example: gh api repos/OWNER/REPO/pulls/PR_NUMBER/comments -q '.[] | {id, path, line, body: .body, user: .user.login, created_at}'

Frequently Asked Questions about Using GitHub API with gh CLI

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I fetch inline PR review comments using GitHub's API?

Use gh api with the REST endpoint /repos/{owner}/{repo}/pulls/{pull_number}/comments to fetch inline review comments. The gh CLI tool retrieves comment metadata including ID, file path, line number, body, author, and timestamps without requiring manual API authentication or token management.

Can I query GitHub pull request review thread status programmatically?

Yes. Use gh api with GraphQL queries to fetch review thread structure and resolved/unresolved status. This retrieves thread state data not exposed by standard gh pr view commands, enabling automated filtering of active vs. resolved review conversations.

What's the difference between REST and GraphQL access for GitHub PR data?

REST endpoints like /repos/{owner}/{repo}/pulls/{pull_number}/reviews return flat comment lists; GraphQL queries expose nested thread structure and resolution status. Choose REST for simple comment extraction and GraphQL when you need hierarchical review data or advanced filtering across thread relationships.

Do I need jq to use the gh API for review data extraction?

No, jq is optional. The gh CLI returns JSON by default; jq enhances filtering and formatting of results. Use the -q flag with gh api to pipe output through jq for selective field extraction, or parse JSON responses directly in your automation script.

How do I extract owner, repo, and PR number from a GitHub URL for API calls?

Parse the URL pattern https://github.com/{owner}/{repo}/pull/{pr_number} to extract these identifiers, then pass them to gh api endpoints. Most automation workflows extract these values from environment variables or git remote URLs to make API calls dynamic and reusable.

What happens when standard gh pr view doesn't show the review data I need?

gh pr view displays basic PR metadata but omits inline review comments and thread status. Use gh api directly to access full REST and GraphQL endpoints, retrieving granular comment data, resolver information, and thread resolution states for comprehensive review analysis.