Created
March 29, 2023 09:13
-
-
Save timja/60b6867a983617c28dfa5c153fe4d08a to your computer and use it in GitHub Desktop.
Removes a specified parent team from all children
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Name of the parent team to remove | |
org="$1" | |
PARENT_TEAM_ID="$2" | |
# Iterate over all teams in the organization | |
items=$(gh api "/orgs/$org/teams" --paginate | jq -c -r '.[]') | |
IFS=$'\n' | |
for team in ${items[@]}; do | |
# Get the parent team of the current team | |
team_slug=$(echo $team | jq -r '.slug') | |
parent_team=$(echo $team | jq -r .parent.id) | |
if [[ "$parent_team" == "$PARENT_TEAM_ID" ]]; then | |
# Remove the parent team from the current team | |
gh api -X PATCH "/orgs/$org/teams/$team_slug" -F "parent_team_id=null" | |
echo "Parent team '$PARENT_TEAM_ID' removed from '$team_slug' team." | |
else | |
echo "'$team_slug' team has a different parent team: '$parent_team'." | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment