Skip to content

Instantly share code, notes, and snippets.

@qqaatw
Created August 3, 2026 14:23
Show Gist options
  • Select an option

  • Save qqaatw/82035f02dee23e2e5be54c98f5b0451c to your computer and use it in GitHub Desktop.

Select an option

Save qqaatw/82035f02dee23e2e5be54c98f5b0451c to your computer and use it in GitHub Desktop.
check_pytorch_access
#!/usr/bin/env bash
# Check if a file was provided as an argument
if [ $# -ne 1 ]; then
echo "Usage: $0 <filename>"
echo "Example: $0 github_ids.txt"
exit 1
fi
INPUT_FILE="$1"
REPO="pytorch/pytorch"
# Check if the file exists
if [ ! -f "$INPUT_FILE" ]; then
echo "Error: File '$INPUT_FILE' not found."
exit 1
fi
# Ensure user is logged into gh cli
if ! gh auth status &>/dev/null; then
echo "Error: You are not logged into GitHub CLI. Please run 'gh auth login' first."
exit 1
fi
echo "Checking roles for repository: $REPO"
echo "------------------------------------------------"
printf "%-25s | %-15s\n" "GitHub ID" "Role"
echo "------------------------------------------------"
# Read the file line by line (handles LF/Unix line endings)
while IFS= read -r username || [ -n "$username" ]; do
# Skip empty lines or lines starting with comments (#)
[[ -z "$username" || "$username" =~ ^# ]] && continue
# Trim whitespace or carriage returns if any
username=$(echo "$username" | tr -d '\r' | xargs)
# Call the GitHub API using gh cli and extract the role_name using jq
# stderr is redirected to /dev/null so API errors don't mess up our clean output
ROLE=$(gh api "repos/$REPO/collaborators/$username/permission" --jq '.role_name' 2>/dev/null)
# Check if the API request was successful / user exists
if [ -z "$ROLE" ]; then
# If the specific permission endpoint fails or returns empty, check if they are an outsider (404)
# or if we are unauthorized to see this specific user's tier.
printf "%-25s | %-15s\n" "$username" "No Access / Hidden"
else
printf "%-25s | %-15s\n" "$username" "$ROLE"
fi
done <"$INPUT_FILE"
echo "------------------------------------------------"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment