Skip to content

Instantly share code, notes, and snippets.

@andersonvom
Last active January 25, 2017 16:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andersonvom/915ca93439acab5f956fe302dddc829e to your computer and use it in GitHub Desktop.
Save andersonvom/915ca93439acab5f956fe302dddc829e to your computer and use it in GitHub Desktop.
This script clones all public repos from a given github organization in parallel
#!/bin/bash
if [ "$1" == "" ]; then
app=$(basename ${0})
echo "Usage: $app <organization_name> [<curl opts>]"
echo " e.g. $app twitter # clone all public repos from <twitter>"
echo " e.g. $app syncthing -u andersonvom # clone all public and private repos from <syncthing> that <andersonvom> has access to"
exit 1
fi
org=${1}
curl_opts=${@:2}
per_page=100
function next_page {
local current_page_number=$1
local next_page_number=$(( $current_page_number + 1 ))
curl $curl_opts -Is "https://api.github.com/orgs/${org}/repos?per_page=${per_page}&page=${current_page_number}" | grep -oe "page=$next_page_number" | cut -d "=" -f2
}
function clone_page {
local page=$1
for repo in $(curl $curl_opts -s "https://api.github.com/orgs/${org}/repos?per_page=${per_page}&page=${page}" |
grep -e "clone_url" |
cut -d ':' -f2- |
sed -e 's/[", ]//g' ); do
echo Cloning $repo ...
git clone --depth 1 $repo &> /dev/null &
done
next_page_number=$(next_page $page)
if [ "$next_page_number" != "" ]; then
clone_page $next_page_number
fi
}
clone_page 1
echo "This might take a while..."
wait
echo "Done!"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment