From ff5883c97e92ac6a1c8b299b0c1ea22edf265868 Mon Sep 17 00:00:00 2001 From: Saravana Dhandapani Date: Sat, 8 Feb 2025 23:56:43 -0800 Subject: [PATCH] ops: add failure reason --- make_repos_private.sh | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/make_repos_private.sh b/make_repos_private.sh index 64168e1..19c4e29 100644 --- a/make_repos_private.sh +++ b/make_repos_private.sh @@ -16,17 +16,39 @@ echo "🔍 Checking and updating repositories to private..." while IFS= read -r REPO_FULL_NAME; do echo "🔄 Processing repository: $REPO_FULL_NAME..." - # Check the current privacy status + # Get repository details REPO_INFO=$(curl -s -H "Authorization: token $GITHUB_TOKEN" \ "https://api.github.com/repos/$REPO_FULL_NAME") IS_PRIVATE=$(echo "$REPO_INFO" | jq -r '.private') + IS_FORK=$(echo "$REPO_INFO" | jq -r '.fork') + HAS_ADMIN_ACCESS=$(echo "$REPO_INFO" | jq -r '.permissions.admin') + IS_GITHUB_PAGES=$(echo "$REPO_INFO" | jq -r '.name' | grep -i '\.github\.io') + # Skip if already private if [[ "$IS_PRIVATE" == "true" ]]; then echo "✅ Repository '$REPO_FULL_NAME' is already private. Skipping..." continue fi + # Skip if the repo is a fork (GitHub doesn't allow making forked repos private) + if [[ "$IS_FORK" == "true" ]]; then + echo "⚠️ Skipping '$REPO_FULL_NAME' because it is a forked repository." + continue + fi + + # Skip if the repo is a GitHub Pages site + if [[ -n "$IS_GITHUB_PAGES" ]]; then + echo "⚠️ Skipping '$REPO_FULL_NAME' because it is a GitHub Pages site." + continue + fi + + # Skip if the user doesn't have admin access + if [[ "$HAS_ADMIN_ACCESS" != "true" ]]; then + echo "❌ Skipping '$REPO_FULL_NAME' because you do NOT have admin permissions." + continue + fi + # Convert the repository to private RESPONSE=$(curl -s -o /dev/null -w "%{http_code}" -X PATCH -H "Authorization: token $GITHUB_TOKEN" \ -H "Accept: application/vnd.github.v3+json" \