This script lists all users with read access to a specified GitHub repository using the GitHub API.
The script performs the following actions:
- Authenticates with the GitHub API using your username and personal access token
- Takes a repository owner and repository name as command line arguments
- Fetches and displays all collaborators who have read (pull) access to the repository
- Bash shell
curl
installedjq
installed (for JSON processing)- GitHub personal access token with appropriate permissions
- Set environment variables for your GitHub credentials:
export username="your_github_username" export token="your_github_personal_access_token"
Run the script with the repository owner and name as arguments:
./list-users.sh <repo_owner> <repo_name>
Example:
./list-users.sh octocat Hello-World
The script will output:
- A list of users with read access to the repository
- Or a message if no users with read access are found
The script includes basic error handling:
- Checks for the required command line arguments
- Provides a usage message if arguments are missing
- Keep your personal access token secure
- Never commit tokens to version control
- Use tokens with the minimum required permissions