Skip to content

Instantly share code, notes, and snippets.

@miparnisari
Last active May 23, 2025 17:23
Show Gist options
  • Save miparnisari/fbb87ab2fbaacc894d8c872dd567a580 to your computer and use it in GitHub Desktop.
Save miparnisari/fbb87ab2fbaacc894d8c872dd567a580 to your computer and use it in GitHub Desktop.
Check for archived repos
#!/bin/bash
set -e
GITHUB_TOKEN=ENTER-YOUR-TOKEN
if [ -z "$1" ]; then
echo "Check for achived repos. \nUsage: $0 <go.md URL or file>"
exit 1
fi
README_URL="$1"
TMP_FILE=$(mktemp)
if [[ "$README_URL" == http://* || "$README_URL" == https://* ]]; then
# It's a URL, download it
echo "Downloading..."
curl -s "$README_URL" -o "$TMP_FILE"
else
# Not a URL, treat README_URL as a local file path or raw content
# If it's a file path, copy it; if raw content, echo it
if [[ -f "$README_URL" ]]; then
cp "$README_URL" "$TMP_FILE"
else
echo "$README_URL" > "$TMP_FILE"
fi
fi
# Extract GitHub repo links (https://github.com/user/repo or with .git, ignore deeper paths)
REPOS=$(grep -oE 'github\.com/[a-zA-Z0-9._-]+/[a-zA-Z0-9._-]+' "$TMP_FILE" | sort -u)
echo
echo "Checking if any repositories are archived..."
echo
for REPO_URL in $REPOS; do
# Extract user and repo
USER_REPO=$(echo "$REPO_URL" | sed -E 's|^.*github\.com/||')
API_URL="https://api.github.com/repos/$USER_REPO"
# Query the GitHub API
response=$(curl -s -H "Authorization: Bearer $GITHUB_TOKEN" "$API_URL")
# Extract the archived field
ARCHIVED=$(echo "$response" | jq -r '.archived')
if [ "$ARCHIVED" = true ]; then
echo "⚠️ Archived: $REPO_URL"
fi
done
# Cleanup
rm "$TMP_FILE"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment