#!/usr/bin/env bash
# nerf-gh-pr-review-comments -- List inline review comments for a single review (by numeric review ID). Use gh-pr-reviews to find review IDs. Returns the raw GitHub API response; pipe through jq to project the fields you want.
# Generated from gh manifest. Do not edit directly.
# nerf:threat:read=remote
# nerf:threat:write=none

set -euo pipefail

_NERF_DRY_RUN=""

usage() {
  cat >&2 <<'EOF'
Usage: nerf-gh-pr-review-comments <pr> <review_id>

Arguments:
  <pr> (required)
      PR number
      Must match: ^[0-9]+$
  <review_id> (required)
      Numeric review ID (from gh-pr-reviews)
      Must match: ^[0-9]+$

Maps to: gh api --paginate --slurp repos/{owner}/{repo}/pulls/<pr>/reviews/<review_id>/comments

List inline review comments for a single review (by numeric review ID). Use gh-pr-reviews to find review IDs. Returns the raw GitHub API response; pipe through jq to project the fields you want.
EOF
  exit 1
}

while [[ $# -gt 0 ]]; do
  case "$1" in
    --nerf-dry-run) _NERF_DRY_RUN="true"; shift 1 ;;
    -h|--help) usage ;;
    --) shift; break ;;
    *) break ;;
  esac
done

_PR_SET=""
if [[ $# -gt 0 ]]; then
  PR="$1"
  _PR_SET=true
  shift
else
  PR=""
fi
_REVIEW_ID_SET=""
if [[ $# -gt 0 ]]; then
  REVIEW_ID="$1"
  _REVIEW_ID_SET=true
  shift
else
  REVIEW_ID=""
fi
if [[ $# -gt 0 ]]; then
  echo "error: nerf-gh-pr-review-comments: unexpected extra arguments: $*" >&2
  echo "  hint: switches and options must come before positional arguments" >&2
  exit 1
fi

if [[ -n "${_PR_SET}" ]] && [[ "${PR}" == -* ]]; then
  echo "error: nerf-gh-pr-review-comments: <pr> cannot start with '-'" >&2
  echo "  hint: use -- before positional arguments if needed" >&2
  exit 1
fi

if [[ -z "${PR}" ]]; then
  echo "error: nerf-gh-pr-review-comments: missing required argument <pr>" >&2
  echo "  hint: provide a value for <pr>" >&2
  usage
fi

_NERF_PATTERN='^[0-9]+$'
if [[ -n "${_PR_SET}" ]] && ! [[ "${PR}" =~ $_NERF_PATTERN ]]; then
  echo "error: nerf-gh-pr-review-comments: argument <pr> does not match required pattern" >&2
  echo "  value:   \"${PR}\"" >&2
  echo "  pattern: ^[0-9]+$" >&2
  echo "  hint: value must match ^[0-9]+$" >&2
  exit 1
fi

if [[ -n "${_REVIEW_ID_SET}" ]] && [[ "${REVIEW_ID}" == -* ]]; then
  echo "error: nerf-gh-pr-review-comments: <review_id> cannot start with '-'" >&2
  echo "  hint: use -- before positional arguments if needed" >&2
  exit 1
fi

if [[ -z "${REVIEW_ID}" ]]; then
  echo "error: nerf-gh-pr-review-comments: missing required argument <review_id>" >&2
  echo "  hint: provide a value for <review_id>" >&2
  usage
fi

_NERF_PATTERN='^[0-9]+$'
if [[ -n "${_REVIEW_ID_SET}" ]] && ! [[ "${REVIEW_ID}" =~ $_NERF_PATTERN ]]; then
  echo "error: nerf-gh-pr-review-comments: argument <review_id> does not match required pattern" >&2
  echo "  value:   \"${REVIEW_ID}\"" >&2
  echo "  pattern: ^[0-9]+$" >&2
  echo "  hint: value must match ^[0-9]+$" >&2
  exit 1
fi

if [[ "$_NERF_DRY_RUN" == "true" ]]; then
  _NERF_DRY_CMD=(gh api --paginate --slurp "repos/{owner}/{repo}/pulls/${PR}/reviews/${REVIEW_ID}/comments")
  printf 'dry-run:'
  for _a in "${_NERF_DRY_CMD[@]}"; do printf " %q" "$_a"; done
  echo
  exit 0
fi

exec gh api --paginate --slurp "repos/{owner}/{repo}/pulls/${PR}/reviews/${REVIEW_ID}/comments"
