Skip to content

Instantly share code, notes, and snippets.

@RichardFevrier
Last active March 24, 2026 17:02
Show Gist options
  • Select an option

  • Save RichardFevrier/b3026bb2416d10e35781d276e9ed2f54 to your computer and use it in GitHub Desktop.

Select an option

Save RichardFevrier/b3026bb2416d10e35781d276e9ed2f54 to your computer and use it in GitHub Desktop.
#!/bin/sh
# fetch_github_issues_by_author.sh
# Fetch GitHub issues by author with pagination support
# Usage (installed):
# fetch_github_issues_by_author.sh [author]
#
# Usage (direct from gist, argument passed to sh via -s):
# curl -fsSL https://gist.github.com/RichardFevrier/b3026bb2416d10e35781d276e9ed2f54/raw/fetch_github_issues_by_author.sh | sh -s <author>
#
# Optional env:
# GITHUB_TOKEN=ghp_xxx — to avoid API rate limits
# ── Dependency check ─────────────────────────────────────────────────────────
if ! command -v curl >/dev/null 2>&1 && ! command -v wget >/dev/null 2>&1; then
printf 'Error: curl or wget is required for GitHub API calls\n' >&2
exit 1
fi
# ── Helpers ──────────────────────────────────────────────────────────────────
# _api_get <url> — fetch URL following redirects, always print body (even on error)
_api_get() (
url="$1"
if command -v curl >/dev/null 2>&1; then
if [ -n "$GITHUB_TOKEN" ]; then
curl -sL -H "Accept: application/vnd.github+json" -H "Authorization: Bearer ${GITHUB_TOKEN}" "$url"
else
curl -sL "$url"
fi
else
if [ -n "$GITHUB_TOKEN" ]; then
wget -qO- --header="Accept: application/vnd.github+json" --header="Authorization: Bearer ${GITHUB_TOKEN}" "$url"
else
wget -qO- "$url"
fi
fi
)
# ── Core predicates ───────────────────────────────────────────────────────────
PER_PAGE=100
TOTAL_PAGES=1
CURRENT_PAGE=1
while [ $CURRENT_PAGE -le $TOTAL_PAGES ]; do
RESPONSE=$(_api_get "https://api.github.com/search/issues?q=author:${1}&per_page=${PER_PAGE}&page=${CURRENT_PAGE}")
# Extract total count from first page response to calculate total pages
if [ $CURRENT_PAGE -eq 1 ]; then
TOTAL_COUNT=$(echo "$RESPONSE" | jq '.total_count // 0')
if [ $TOTAL_COUNT -eq 0 ]; then
break
fi
TOTAL_PAGES=$(( (TOTAL_COUNT + PER_PAGE - 1) / PER_PAGE ))
fi
# Output issues for this page
echo "$RESPONSE" | jq --arg page "$CURRENT_PAGE" '.items[] | {title: .title, body: .body}'
CURRENT_PAGE=$((CURRENT_PAGE + 1))
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment