Created
November 27, 2017 05:21
-
-
Save polster/3b20c208e66482c48043656da963bd44 to your computer and use it in GitHub Desktop.
Gitlab project sync script
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 -x | |
GITLAB_USER_ID="yourUserId" | |
GITLAB_PRIVATE_TOKEN="yourPrivateToken" | |
GITLAB_API_BASE="https://gitlab.com/api/v3" | |
GITLAB_LOCAL_DIR_BASE="${HOME}/Dev/Git" | |
repo_urls=$(curl -s "${GITLAB_API_BASE}/users/${GITLAB_USER_ID}/projects?private_token=${GITLAB_PRIVATE_TOKEN}&per_page=999" \ | |
| jq -r '.[] | .ssh_url_to_repo') | |
cd ${GITLAB_LOCAL_DIR_BASE} | |
for repo_url in $repo_urls; do | |
repo_name=$(echo $repo_url | egrep -o '[^\/]+\.git') | |
dir=${repo_name%.git} | |
if [ ! -d $dir ]; then | |
echo "Found new component: $dir" | |
git clone $repo_url $dir | |
fi | |
git -C $dir status | |
git -C $dir pull --rebase | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment