|
| 1 | +#!/usr/bin/env bash |
| 2 | +# |
| 3 | +# export_issues_with_release.sh |
| 4 | +# ----------------------------- |
| 5 | +# Export all issues from a GitHub repository to CSV, including |
| 6 | +# the milestone (treated as the "release") name & description. |
| 7 | +# |
| 8 | +# Prerequisites |
| 9 | +# - GitHub CLI (`gh`) logged-in with repo read scope |
| 10 | +# - jq 1.6+ |
| 11 | +# |
| 12 | +# Usage |
| 13 | +# ./export_issues_with_release.sh [output.csv] |
| 14 | +# |
| 15 | +# Environment overrides |
| 16 | +# REPO - target repo in OWNER/NAME form (default: current directory's repo) |
| 17 | +# STATE - issue states to include: open|closed|all (default: all) |
| 18 | +# LIMIT - max issues to fetch (default: 9999) |
| 19 | +# |
| 20 | +# Example |
| 21 | +# ./export_issues_with_release.sh /tmp/issues.csv |
| 22 | +# |
| 23 | + |
| 24 | +set -euo pipefail |
| 25 | + |
| 26 | +### Config -------------------------------------------------------------------- |
| 27 | +OUTPUT="${1:-issues.csv}" |
| 28 | +STATE="${STATE:-all}" # open|closed|all |
| 29 | +LIMIT="${LIMIT:-9999}" |
| 30 | +REPO="${REPO:-$(gh repo view --json nameWithOwner -q .nameWithOwner)}" |
| 31 | + |
| 32 | +### Fetch & transform --------------------------------------------------------- |
| 33 | +echo "📦 Exporting issues for $REPO (state=$STATE, limit=$LIMIT) ..." |
| 34 | + |
| 35 | +gh issue list --repo "$REPO" \ |
| 36 | + --state "$STATE" --limit "$LIMIT" \ |
| 37 | + --json number,title,state,milestone \ |
| 38 | + --jq ' |
| 39 | + # ---- emit CSV header first |
| 40 | + (["issue_number","title","state","release","release_description"] | @csv), |
| 41 | + # ---- then one CSV row per issue |
| 42 | + (.[] | |
| 43 | + [ .number, |
| 44 | + (.title | gsub("\n"; " ") ), # strip line-breaks |
| 45 | + .state, |
| 46 | + ( .milestone.title // "" ), |
| 47 | + ( .milestone.description // "" | gsub("\r?\n"; " ") ) |
| 48 | + ] | @csv) |
| 49 | + ' > "$OUTPUT" |
| 50 | + |
| 51 | +echo "✅ Wrote $(wc -l <"$OUTPUT") lines to $OUTPUT" |
0 commit comments