Github API Integration
Sayan Bose
DevOps Engineer || SRE/DevOps || Kubernetes | Docker | AWS | Git | Terraform | GCP | Linux | Shell Scripting | Github | Jenkins
Created the above shell script which will list no.of users for a organisation's repository in Github.
It basically helps to list users who have read access in your repo and so it'll help u in identifying the list and also revoke the access for any user who left's the org/project or so on.
Explanation of code:
API_URL="https://api.github.com":
GitHub Username and Token:
Repository Information:
function github_api_get { local endpoint="$1" local url="${API_URL}/${endpoint}" curl -s -u "${USERNAME}:${TOKEN}" "$url" }
local endpoint="$1":
local url="${API_URL}/${endpoint}":
curl -s -u "${USERNAME}:${TOKEN}" "$url":
领英推荐
2. Function to List Users with Read Access
function list_users_with_read_access { local endpoint="repos/${REPO_OWNER}/${REPO_NAME}/collaborators" collaborators="$(github_api_get "$endpoint" | jq -r '.[] | select(.permissions.pull == true) | .login')" 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 }
local endpoint="repos/${REPO_OWNER}/${REPO_NAME}/collaborators":
collaborators="$(github_api_get "$endpoint" | jq -r '.[] | select(.permissions.pull == true) | .login')":
| jq -r '.[] | select(.permissions.pull == true) | .login':
if [[ -z "$collaborators" ]]; then:
-z checks if collaborators is empty. If it’s empty, it means there are no users with read access.
#devops
#SRE
#ShellScripting