Skip to content

Instantly share code, notes, and snippets.

@timja
Created March 29, 2023 09:13
Show Gist options
  • Save timja/60b6867a983617c28dfa5c153fe4d08a to your computer and use it in GitHub Desktop.
Save timja/60b6867a983617c28dfa5c153fe4d08a to your computer and use it in GitHub Desktop.
Removes a specified parent team from all children
#!/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