Created
April 13, 2023 16:34
-
-
Save lukaszraczylo/1de084acd3eaf425f52757380085e643 to your computer and use it in GitHub Desktop.
Archive old github repositories for user/organisation
This file contains hidden or 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
#!/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