Skip to content

Instantly share code, notes, and snippets.

@horothesun
Last active June 4, 2023 10:05
Show Gist options
  • Save horothesun/a87e3d126f4748e48829a6a646714864 to your computer and use it in GitHub Desktop.
Save horothesun/a87e3d126f4748e48829a6a646714864 to your computer and use it in GitHub Desktop.
Get all GitHub secrets
#!/bin/bash
# Usage: ./get_all_gh_secrets.sh "<OWNER>" "100"
GITHUB_OWNER=$1
MAX_NUMBER_OF_REPOS=$2
[[ -z "${GITHUB_OWNER}" ]] && echo "Error: GITHUB_OWNER must be passed as first parameter" && exit 10
[[ -z "${MAX_NUMBER_OF_REPOS}" ]] && echo "Error: MAX_NUMBER_OF_REPOS must be passed as second parameter" && exit 20
REPOS_NAME_WITH_OWNER=$(
gh repo list "${GITHUB_OWNER}" \
--limit "${MAX_NUMBER_OF_REPOS}" \
--source \
--json "nameWithOwner"
)
REPOS_COUNT=$(echo "${REPOS_NAME_WITH_OWNER}" | jq 'length')
echo "Repos retrieved: ${REPOS_COUNT}"
echo
echo ---
echo
echo "Secrets:"
echo
echo "${REPOS_NAME_WITH_OWNER}" |\
jq --raw-output 'sort_by(.nameWithOwner)[] | .nameWithOwner' |\
xargs -I ^ bash -c "echo Repo: ^ && gh secret --repo ^ list | cat ; echo "
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment