helpers/shell/gh-repo.sh

22 lines
634 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")
GH_REPO_ORGS="example"
GH_REPO_DIST="dist/${me%.*}"
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