helpers/shell/gh-repo.sh

23 lines
681 B
Bash
Raw Normal View History

2023-08-17 08:12:48 +00:00
#!/usr/bin/env bash
## requirements: gh, jq
## manual gh login needs to be executed first
set -eo pipefail
me=$(basename "$0")
2023-08-17 08:53:11 +00:00
dist="dist/${me%.*}"
2023-08-17 08:12:48 +00:00
2023-08-17 08:53:11 +00:00
GH_REPO_ORGS="${GH_REPO_ORGS:-example}"
GH_REPO_DIST="${GH_REPO_DIST:-$dist}"
2023-08-17 08:12:48 +00:00
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