helpers/shell/gh-repo.sh
Robert Kaussow 09a88c17ea
All checks were successful
continuous-integration/drone/push Build is passing
allow env var overwrite
2023-08-17 10:53:11 +02:00

23 lines
681 B
Bash
Executable File

#!/usr/bin/env bash
## requirements: gh, jq
## manual gh login needs to be executed first
set -eo pipefail
me=$(basename "$0")
dist="dist/${me%.*}"
GH_REPO_ORGS="${GH_REPO_ORGS:-example}"
GH_REPO_DIST="${GH_REPO_DIST:-$dist}"
mkdir -p "${GH_REPO_DIST}"
echo "Org,Repository,Private" >"${GH_REPO_DIST}/github-repositories.csv"
for org in ${GH_REPO_ORGS}; do
printf "Processing '%s'\n" "${org}"
# gh -jq flag does not work for error filtering
gh api "search/repositories?q=org:${org}" --paginate |
jq -r 'select(.items != null).items[] | [.owner.login, .full_name, .private] | @csv' \
>>"${GH_REPO_DIST}/github-repositories.csv" || continue
done