Skip to content

Instantly share code, notes, and snippets.

@luislobo
Created March 25, 2021 23:20
Show Gist options
  • Save luislobo/5ab28f6e53583575814964f897ecb33e to your computer and use it in GitHub Desktop.
Save luislobo/5ab28f6e53583575814964f897ecb33e to your computer and use it in GitHub Desktop.
Clones all repositories you have access to in Bitbucket.org (using API 2.0 and workspaces)
#!/bin/bash
cwd=`pwd`
USER=username
PASS=password
SLUG=your_slug # this is the project team name you see in the url
repoUrl=`curl -s --user ${USER}:${PASS} "https://api.bitbucket.org/2.0/workspaces?q=slug=\"${SLUG}\"" | jq -r '.values[] | .links.repositories.href'`
for i in {1..2}; do
repos=$repos`curl -s --user ${USER}:${PASS} "${repoUrl}?pagelen=100" | jq -r '.values[] | .links.clone[1].href'`
done
for repo in ${repos}; do
projectname=`basename ${repo}`
if [[ $repo == *".git" ]]; then
echo "It's a git!"
command="git"
else
echo "It's a mercurial!"
command="hg"
fi
if [ -d "$projectname" ]; then
echo "Project directory exists. $repo will be updated"
cd $cwd/$projectname
$command pull
cd $cwd
else
echo "Cloning" $repo
$command clone $repo
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment