#!/bin/bash # Load environment variables GITHUB_TOKEN="${GITHUB_TOKEN:?❌ Error: GITHUB_TOKEN is not set}" REPO_LIST_FILE="repos.txt" # Name of the file containing the repo list # Ensure the file exists if [[ ! -f "$REPO_LIST_FILE" ]]; then echo "❌ Error: File '$REPO_LIST_FILE' not found!" exit 1 fi echo "🔍 Checking and updating repositories to private..." # Loop through each repository in the file while IFS= read -r REPO_FULL_NAME; do echo "🔄 Processing repository: $REPO_FULL_NAME..." # Check the current privacy status 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') if [[ "$IS_PRIVATE" == "true" ]]; then echo "✅ Repository '$REPO_FULL_NAME' is already private. Skipping..." 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" \ -d '{"private": true}' \ "https://api.github.com/repos/$REPO_FULL_NAME") if [[ "$RESPONSE" -eq 200 ]]; then echo "✅ Successfully converted '$REPO_FULL_NAME' to private." else echo "❌ Failed to make '$REPO_FULL_NAME' private. HTTP Status: $RESPONSE" fi done < "$REPO_LIST_FILE" echo "✅ All repositories processed."