Skip to content

Instantly share code, notes, and snippets.

@lukaszraczylo
Created April 13, 2023 16:34
Show Gist options
  • Save lukaszraczylo/1de084acd3eaf425f52757380085e643 to your computer and use it in GitHub Desktop.
Save lukaszraczylo/1de084acd3eaf425f52757380085e643 to your computer and use it in GitHub Desktop.
Archive old github repositories for user/organisation
#!/bin/bash
# This script will archive all repositories on github where
# the last commit was more than 2 years ago.
# It takes one argument, the github username / organisation name.
organisationName=$1
if [ -z "$organisationName" ]; then
echo "Please provide organisation name"
exit 1
fi
__listGitRepositoriesInOrganisation() {
listOfRepositories=$(gh search repos --owner "$organisationName" --sort updated --order desc --json name,updatedAt --limit 1000 | jq -r '.[] | select(.updatedAt < "2021-01-01") | .name')
}
__archiveAllRepositories() {
for repository in $listOfRepositories; do
echo "Archiving $repository"
gh repo archive $organisationName/$repository -y
done
}
__listGitRepositoriesInOrganisation
__archiveAllRepositories "$listOfRepositories"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment