Skip to content

Instantly share code, notes, and snippets.

@jonchurch
Created November 10, 2024 20:02
Show Gist options
  • Save jonchurch/0ebe42ddba5f731f82cd584d0c611011 to your computer and use it in GitHub Desktop.
Save jonchurch/0ebe42ddba5f731f82cd584d0c611011 to your computer and use it in GitHub Desktop.
Get all GH releaes from a repo in a flat file, using gh cli
#!/bin/sh
# Check if gh CLI is installed
if ! command -v gh >/dev/null 2>&1; then
echo "Error: GitHub CLI (gh) is not installed. Please install it to continue." >&2
exit 1
fi
# Check if a repository identifier was provided
if [ -z "$1" ]; then
echo "Usage: $0 <GitHub repository URL or owner/repo>" >&2
exit 1
fi
# Extract the owner and repo name from the input by splitting on /
INPUT="$1"
OWNER=$(echo "$INPUT" | awk -F '/' '{print $(NF-1)}')
REPO=$(echo "$INPUT" | awk -F '/' '{print $NF}')
# Fetch all releases directly
gh api --paginate "repos/$OWNER/$REPO/releases" | jq -r '.[] | "## \(.tag_name)\n\n\(.body // "No release notes")\n\n---\n"'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment