Skip to content

Add script for creating teams in bulk in github orgs #370

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Oct 9, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions api/bash/create-teams.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#!/bin/bash
# Replace the "xxxxx" with the required values
# Author: @ppremk

# Script to create GitHub Teams in bulk on GitHub.com Organization
# PAT Tokens needs to have the correct scope to be able to create teams in an organization
# Teams are added as an Array. Teams are created as stand alone teams. Team relationship is not defined

# To run the script:
#
# - Update VARS section in script
# - chmod +x script.sh
# - ./script.sh

# VARS
orgname="xxx"
pattoken="xxxxxxx"
teams=("team-name-1" "team-name-2")

echo "Bulk creating teams in:"
echo $orgname

for i in "${teams[@]}"
do
curl --request POST \
--url "https://api.github.com/orgs/$orgname/teams" \
--header "accept: application/vnd.github.v3+json" \
--header "authorization: Bearer ${pattoken}" \
--header "content-type: application/json" \
--data "{\"name\": \"$i\", \"privacy\": \"closed\" }" \
-- fail

retVal=$?
if [ $retVal -ne 0 ]; then
echo "Team creation failed! Please verify validity of supplied configurations."
exit 1
fi
done
echo "Teams succesfully created!"