Last active
May 15, 2023 09:17
-
-
Save KeyboardInterrupt/357b7f93e491d649522ee0e8334e7f22 to your computer and use it in GitHub Desktop.
Clone all Git Projects in a Gitlab Group, including Subgroups, by ID
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 | |
if [ -z ${GITLAB_BASE_PATH+x} ]; then | |
read -p "GITLAB_BASE_PATH: " -r GITLAB_BASE_PATH | |
fi | |
if [ -z ${GITLAB_READONLY_PRIVATE_TOKEN+x} ]; then | |
read -p "GITLAB_READONLY_PRIVATE_TOKEN: " -r GITLAB_READONLY_PRIVATE_TOKEN | |
fi | |
if [ -z ${GROUP_ID+x} ]; then | |
read -p "GROUP_ID: " -r GROUP_ID | |
fi | |
SLEEP_DURATION=5 | |
echo "Cloning all git projects in group ${GROUP_ID}"; | |
REPO_SSH_URLS=$(curl -s "${GITLAB_BASE_PATH}api/v4/groups/${GROUP_ID}/projects?private_token=${GITLAB_READONLY_PRIVATE_TOKEN}&per_page=999&include_subgroups=true" \ | |
| jq -r '.[] | .ssh_url_to_repo') | |
for REPO_SSH_URL in ${REPO_SSH_URLS}; do | |
THEPATH=$(echo ${REPO_SSH_URL} | cut -d":" -f 2 | cut -d"." -f 1) | |
if [ ! -d "${THEPATH}" ]; then | |
echo "Cloning $THEPATH ( $REPO_SSH_URL )" | |
mkdir -p "${THEPATH}" | |
git clone ${REPO_SSH_URL} ${THEPATH} | |
else | |
echo "Pulling $THEPATH ( $REPO_SSH_URL )" | |
(cd ${THEPATH} && git pull) | |
fi | |
echo "sleeping ${SLEEP_DURATION} seconds" | |
sleep ${SLEEP_DURATION} | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment