-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlist-users.sh
More file actions
67 lines (48 loc) · 1.64 KB
/
list-users.sh
File metadata and controls
67 lines (48 loc) · 1.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#!/bin/bash
###########################################
#about:
#Input:
#
# Owner:
#
# version = v1
# This script will fetch "usernames" with "read access" of given github-repo.
###########################################
helper()
# 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')"
collaborators="$(github_api_get "$endpoint" | jq -r '.[] | select(.permissions.admin == false) | .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
}
function helper{
expected_cmd_args=2
if [ $# -ne $expected_cmd_args ]; then
echo "please execute the script with required cmd args"
}
# Main script
echo "Listing users with read access to ${REPO_OWNER}/${REPO_NAME}..."
list_users_with_read_access