#!/bin/bash
# View a GitHub release for an existing tag using gh CLI. Read-only.
#
# Usage:
#   view-release.sh <tag>
#
# Prints the release as JSON. gh exits nonzero with "release not found" when
# the tag exists but has no release, which is the check to run before
# create-release.sh.

set -e

# Arguments
TAG="$1"

# Validation
if [ -z "$TAG" ]; then
    echo "Error: Missing tag" >&2
    echo "Usage: $0 <tag>" >&2
    exit 1
fi

# Check if gh is installed
if ! command -v gh &> /dev/null; then
    echo "Error: GitHub CLI (gh) is not installed" >&2
    exit 1
fi

# Get release details
gh release view "$TAG" \
    --json tagName,name,url,isDraft,isPrerelease,publishedAt,body \
    --jq '.'
