Created
January 11, 2022 16:26
-
-
Save horothesun/aefac04967f3fd7a406899b9b7a45432 to your computer and use it in GitHub Desktop.
Clone all team repos
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Usage: GITHUB_OWNER=<owner> GITHUB_TEAM=<team> clone_all_team_repos.sh | |
# | |
# Dependencies: gh, jq | |
[ -z "$GITHUB_OWNER" ] && echo "Error: GITHUB_OWNER must be defined" && exit 10 | |
[ -z "$GITHUB_TEAM" ] && echo "Error: GITHUB_TEAM must be defined" && exit 20 | |
function cloneIfDoesNotExist() { | |
if [ ! -d "$1" ]; then | |
FULL_REPO=$GITHUB_OWNER/$1 | |
echo "⬇️ Cloning $FULL_REPO ..." | |
gh repo clone $FULL_REPO | |
else | |
echo "👍 $1 already exists!" | |
fi | |
} | |
TEAM_REPOS=$(gh api /orgs/$GITHUB_OWNER/teams/$GITHUB_TEAM/repos\?per_page=100 --paginate | jq -r '.[].name') | |
for REPO in $TEAM_REPOS; do cloneIfDoesNotExist $REPO; done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment