Created
June 15, 2020 21:06
-
-
Save ahpook/60be4a775ba81ea40578000aad13504c to your computer and use it in GitHub Desktop.
Loop over all the repos in the integrations org and... do stuff
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
#!/usr/local/bin/zsh | |
set -x | |
# if we get above 60 repos this will need an update | |
if [[ ! -f repos.json ]]; then | |
curl -s 'https://api.github.com/organizations/62306501/repos?page=1' >! repos.json | |
curl -s 'https://api.github.com/organizations/62306501/repos?page=2' >> repos.json | |
fi | |
directories=("${(@f)$(jq -r 'to_entries|.[].value.name' <repos.json)}") | |
clone_urls=("${(@f)$(jq -r 'to_entries|.[].value.ssh_url' <repos.json)}") | |
function update_repos() { | |
for line in {1..${#directories}}; do | |
if [[ ! -d $directories[$line] ]]; then | |
git clone $clone_urls[$line] | |
else | |
(cd $directories[$line] && git pull) | |
fi | |
done | |
} | |
function purge_actions() { | |
for line in {1..${#directories}}; do | |
repo=${directories[$line]} | |
if [[ -d "$repo/actions" ]]; then | |
(cd $repo && git mv actions/* .) | |
fi | |
if [[ -d "$repo/queries" ]]; then | |
(cd $repo && git rm -r queries) | |
fi | |
if [[ ! $(cd $repo && git status | grep clean) ]]; then | |
(cd $repo && git commit -am "The Great Actions Purge, part 2.5" && \ | |
git push origin master) | |
fi | |
done | |
} | |
update_repos | |
purge_actions |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment