Skip to content

Instantly share code, notes, and snippets.

@DattatreyaReddy
Last active January 29, 2025 14:03
Show Gist options
  • Save DattatreyaReddy/7b260cba90cbf9fad28767f4abef517d to your computer and use it in GitHub Desktop.
Save DattatreyaReddy/7b260cba90cbf9fad28767f4abef517d to your computer and use it in GitHub Desktop.
get pull request review comments and files
#!/bin/bash
# Exit on error
set -e
# Ensure PR number is provided
if [ -z "$1" ]; then
echo "Usage: $0 <PR_NUMBER>"
exit 1
fi
# Get PR number from the first argument
PR_NUMBER=$1
# Extract GitHub owner and repo from the current Git remote
REPO_URL=$(git config --get remote.origin.url)
if [[ $REPO_URL == *"github.com"* ]]; then
OWNER_REPO=$(echo "$REPO_URL" | sed -E 's#(.*github.com[:/])([^/]+)/([^/.]+)(.git)?#\2/\3#')
else
echo "Error: This script must be run inside a GitHub repository folder."
exit 1
fi
# Get the absolute path of the repository (so it's clickable in the terminal)
REPO_DIR=$(pwd)
# Fetch review comments with file paths, line numbers, and format output
gh api repos/$OWNER_REPO/pulls/$PR_NUMBER/comments --jq \
'.[] | "File: file://'"$REPO_DIR"'/" + .path + ":" + (.original_line|tostring) + "\nComment: " + .body + "\n"' | less
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment