-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathremove_repo_access_from_teams.sh
More file actions
41 lines (31 loc) · 1.23 KB
/
remove_repo_access_from_teams.sh
File metadata and controls
41 lines (31 loc) · 1.23 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
#! /bin/bash
ORGANIZATION=$1
TEAM_NAME=$2
REPO_NAMES=$3
PERMISSION=$4
PER_PAGE=100
# List all teams in the organization
list_all_team_details=$(curl -L \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer $GH_TOKEN" \
-H "X-GitHub-Api-Version: 2022-11-28" \
https://api.github.com/orgs/$ORGANIZATION/teams?per_page=$PER_PAGE)
echo $list_all_team_details
# Use jq to extract the slug based on the team name
TEAM_SLUG=$(echo "$list_all_team_details" | jq -r ".[] | select(.name == \"$TEAM_NAME\") | .slug")
echo "Team name: $TEAM_NAME | Team slug name is: $TEAM_SLUG"
# Split the comma-separated values into an array
IFS=',' read -ra repo_array <<< "$REPO_NAMES"
# Iterate over each repository name
for repo_name in "${repo_array[@]}"; do
echo "Processing repository: $repo_name"
response=$(curl -L \
-X DELETE \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer $GH_TOKEN" \
-H "X-GitHub-Api-Version: 2022-11-28" \
"https://api.github.com/orgs/$ORGANIZATION/teams/$TEAM_SLUG/repos/$ORGANIZATION/$repo_name" \
-d "{\"permission\":\"$PERMISSION\"}")
echo "Removed repository: $repo_name from $TEAM_NAME"
done
echo "Execution completed."