Created
March 2, 2016 05:40
-
-
Save l8nite/e136dd221458dd4a9dd3 to your computer and use it in GitHub Desktop.
Clone all repositories in stash that you have access to
This file contains hidden or 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 | |
if [[ "$STASH_USER" == "" || "$STASH_PASS" == "" ]]; then | |
echo "FATAL: You need to set STASH_USER and/or STASH_PASS" | |
exit 1 | |
fi | |
STASH_HOST=${STASH_HOST:-stash.hq.practicefusion.com} | |
STASH_URL=https://${STASH_USER}:${STASH_PASS}@${STASH_HOST} | |
while read projectPath; do | |
projectName=$(echo $projectPath | sed -e 's/^\/projects\///') | |
while read cloneUrl; do | |
repoName=$(basename $cloneUrl | sed -e 's/\.git$//') | |
projectJson=$(curl -k -s ${STASH_URL}/rest/api/1.0${projectPath}/repos/${repoName}) | |
# ignore forks | |
if echo $projectJson | jq -e 'has("origin")' &>/dev/null; then | |
continue; | |
fi | |
# ignore the DEAD project (deprecated/unused code) | |
if [[ "$projectName" == "DEAD" ]]; then | |
continue; | |
fi | |
defaultBranch=$(curl -k -s ${STASH_URL}/rest/api/1.0${projectPath}/repos/${repoName}/branches/default | jq '.displayId') | |
echo "Fetching $projectName/$repoName ($defaultBranch)..." | |
mkdir -p $projectName | |
pushd $projectName &>/dev/null | |
if [[ -d $repoName/.git ]]; then | |
pushd $repoName &>/dev/null | |
sem --jobs 20 --id $projectName "git fetch; git checkout $defaultBranch; git pull --rebase" | |
popd &>/dev/null | |
else | |
sem --jobs 20 --id $projectName "git clone $cloneUrl" | |
fi | |
popd &>/dev/null | |
done < <(curl -k -s ${STASH_URL}/rest/api/1.0${projectPath}/repos?limit=500 | jq -r '.values[].links.clone[] | select(.name=="ssh") | .href') | |
sem --wait --id $projectName | |
done < <(curl -k -s ${STASH_URL}/rest/api/1.0/projects?limit=500 | jq -r '.values[].link.url') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Obviously has some specifics (like the default STASH_HOST and skipping a project named DEAD) from my use case, but it should be easy to adapt. Runs 20 clones/fetches at a time.