Last active
February 13, 2020 03:20
-
-
Save chrisdlangton/a59e85386ed741cb517177816b8d0823 to your computer and use it in GitHub Desktop.
Quick clone all org repos using Github Enterprise API v3
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
#!/usr/bin/env bash | |
RED='\033[0;31m' | |
GREEN='\033[0;32m' | |
YELLOW='\033[0;33m' | |
NC='\033[0m' # No Color | |
if [[ $EUID -eq 0 ]]; then | |
echo -e "${RED}x${NC} This script must not be run as root" | |
exit 1 | |
fi | |
github_host="..." | |
prefix_url="https://${github_host}" | |
declare -a groups=( | |
# "ics" | |
"anzx" | |
# "ex" | |
# "platforms" | |
# "sre" | |
# "csp" | |
) | |
CWD=$(pwd) | |
WORKDIR=${HOME}/workspace | |
mkdir -p ${WORKDIR} | |
cd ${WORKDIR} | |
for group in "${groups[@]}" | |
do | |
echo -e "${YELLOW}>${NC} Query github for repos" | |
repos=$(wget -q --no-check-certificate ${prefix_url}/api/v3/orgs/${group}/repos\?type=sources -O- | jq -r '.[].name') | |
mkdir -p ${group} | |
cd ${group} | |
while read -r repo; do | |
if [[ ! -d ${repo} ]]; then | |
echo -e "${YELLOW}>${NC} Cloning ${group}/${repo}" | |
git clone -q ${prefix_url}/${group}/${repo}.git && \ | |
echo -e "${GREEN}✔${NC} Cloned" | |
cd ${repo} | |
echo -e "${YELLOW}>${NC} Use SSH remote" | |
git remote remove origin && \ | |
git remote add origin git@${github_host}:${group}/${repo}.git && \ | |
echo -e "${GREEN}✔${NC} Using SSH remote" | |
else | |
cd ${repo} | |
echo -e "${YELLOW}>${NC} Git pull" | |
git pull origin master -q && \ | |
echo -e "${GREEN}✔${NC} Updated" | |
fi | |
cd ${WORKDIR}/${group} | |
done <<< "${repos}" | |
cd ${WORKDIR} | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment