Created
May 31, 2026 04:30
-
-
Save igmarin/e86d134a7a0fc7cd72730454e0500358 to your computer and use it in GitHub Desktop.
bash auto_achive.sh (auto achive all project that do not have activity in the last 6 months
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 | |
| # 1. Your GitHub username | |
| USERNAME="yourusername" | |
| # Set this to 'true' to test the script without actually archiving anything | |
| DRY_RUN=true | |
| # 2. Calculate the cutoff date (6 months ago) | |
| if [[ "$OSTYPE" == "darwin"* ]]; then | |
| CUTOFF_DATE=$(date -v-6m +%Y-%m-%dT%H:%M:%SZ) | |
| else | |
| CUTOFF_DATE=$(date -d "6 months ago" +%Y-%m-%dT%H:%M:%SZ) | |
| fi | |
| echo "π Looking for repositories with no activity since: $CUTOFF_DATE" | |
| if [ "$DRY_RUN" = true ]; then | |
| echo "π DRY RUN ACTIVE: No real changes will be made." | |
| fi | |
| echo "--------------------------------------------------------" | |
| # 3. Fetch, filter, and archive repos (excluding forks, including private ones) | |
| gh repo list $USERNAME --limit 1000 --source --no-archived --json name,pushedAt --jq ".[] | select(.pushedAt < \"$CUTOFF_DATE\") | .name" | while read -r repo; do | |
| if [ "$DRY_RUN" = true ]; then | |
| echo "π [Simulation] Would archive: $USERNAME/$repo (Last push: over 6 months ago)" | |
| else | |
| echo "π¦ Archiving $USERNAME/$repo..." | |
| gh repo archive "$USERNAME/$repo" --yes | |
| fi | |
| done | |
| echo "--------------------------------------------------------" | |
| echo "β Process complete!" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment