Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create shellScript.sh #25

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

devilraj98
Copy link

#!/bin/bash

GitHub API URL

API_URL="https://api.github.com"

GitHub username and personal access token

USERNAME=$username
TOKEN=$token

User and Repository information

REPO_OWNER=$1
REPO_NAME=$2

Function to make a GET request to the GitHub API

function github_api_get {
local endpoint="$1"
local url="${API_URL}/${endpoint}"

# Send a GET request to the GitHub API with authentication
curl -s -u "${USERNAME}:${TOKEN}" "$url"

}

Function to list users with read access to the repository

function list_users_with_read_access {
local endpoint="repos/${REPO_OWNER}/${REPO_NAME}/collaborators"

# Fetch the list of collaborators on the repository
collaborators="$(github_api_get "$endpoint" | jq -r '.[] | select(.permissions.pull == true) | .login')"

# Display the list of collaborators with read access
if [[ -z "$collaborators" ]]; then
    echo "No users with read access found for ${REPO_OWNER}/${REPO_NAME}."
else
    echo "Users with read access to ${REPO_OWNER}/${REPO_NAME}:"
    echo "$collaborators"
fi

}

Main script

echo "Listing users with read access to ${REPO_OWNER}/${REPO_NAME}..."
list_users_with_read_access

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant