Skip to content

Instantly share code, notes, and snippets.

@lloesche
Last active February 7, 2019 15:13
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 lloesche/a441f8ed020fd73e45ed8d5499d302fe to your computer and use it in GitHub Desktop.
Save lloesche/a441f8ed020fd73e45ed8d5499d302fe to your computer and use it in GitHub Desktop.
Checkout/Pull all repos of a Github organization
#!/bin/bash
set -o errexit -o pipefail
org=dcos-terraform
parallel=10
function main {
local num_repos=-1
local page=1
local i
local x
local y
declare -a repos
echo "Fetching list of repos in Github organization $org"
until [ $num_repos -eq 0 ]; do
fetched_repos=($(curl "https://api.github.com/orgs/$org/repos?per_page=100&page=$page" 2>/dev/null | jq -r .[].name))
num_repos=${#fetched_repos[@]}
repos+=( "${fetched_repos[@]}" )
let page++
done
echo "Found a total of ${#repos[@]} repos"
for (( x=0; x<$((${#repos[@]}/$parallel)); x++ )); do
for (( y=0; y<$parallel; y++ )); do
i=$(($x*$parallel+$y))
checkout "${repos[$i]}" &
done
wait
done
for (( x=0; x<$((${#repos[@]}%$parallel)); x++ )); do
let i++
checkout "${repos[$i]}" &
done
wait
}
function checkout {
local repo=$1
echo "Pulling or cloning $repo"
if [ -d $repo ]; then
cd "$repo"
git checkout master
git pull
cd ..
else
git clone "git@github.com:$org/$repo.git"
fi
}
main
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment