Skip to content

Instantly share code, notes, and snippets.

@debo
Last active December 22, 2022 17:46
Show Gist options
  • Save debo/1dd9228c626af6512e2d09bd498f380f to your computer and use it in GitHub Desktop.
Save debo/1dd9228c626af6512e2d09bd498f380f to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
GITHUB_BASE_URL="https://api.github.com"
GITHUB_ORGANIZATION="${PWD##*/}"
GITHUB_API_TOKEN=""
for repo in `curl -H "Authorization: Bearer $GITHUB_API_TOKEN" "$GITHUB_BASE_URL/orgs/$GITHUB_ORGANIZATION/repos?per_page=100" | jq '.[] | select( .archived == false ) | .ssh_url' | sed 's/"//g' | sed 's/null//g' | sed '/^\s*$/d' | sort`; do
folder=`basename -s .git $repo`
if [ ! -d $folder ]; then
git clone $repo
else
cd $folder
branch=`git branch | grep \* | cut -d ' ' -f2`
default_branch=`git remote show origin | grep 'HEAD branch' | cut -d' ' -f5`
git fetch --all --prune
git stash
git checkout $default_branch
git pull
git checkout $branch
git stash pop
cd ..
fi
done
for repo in `curl -H "Authorization: Bearer $GITHUB_API_TOKEN" "$GITHUB_BASE_URL/orgs/$GITHUB_ORGANIZATION/repos?per_page=100" | jq '.[] | select( .archived == true ) | .ssh_url' | sed 's/"//g' | sed 's/null//g' | sed '/^\s*$/d' | sort`; do
folder=`basename -s .git $repo`
if [ -d $folder ]; then
rm -rf $folder
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment