GitHub: Scripts to Mass Create and Delete Teams
Create and delete GitHub teams programmatically from a CSV file
Overview
If you’ve ever had to create several teams in GitHub, you know how painful it can be clicking around manually in the GitHub interface, especially if you have to create child teams. These scripts aim to simplify that by providing a list of teams that you want to create (or delete) in a CSV, and then looping through each team and creating (or deleting) it with the gh api
command of the gh cli
.
The Scripts
These scripts are in my github-misc-scripts repo:
Using the Scripts
Prerequisites
- You need to make sure to have the
gh cli
installed and authorized (gh auth login
). - Add the
admin:org
scope:1
gh auth refresh -h github.com -s admin:org
Example Input File
An example of input file that can be used for both creating/deleting teams:
1
2
3
4
5
6
test11-team
test22-team
test11-team/test11111-team
test11-team/test11111-team/textxxx-team
test33-team
Note: Ensure that the input file has a trailing new line
Create Teams
- Prepare a list of teams that you want to create and place in a CSV file, one per line, with the last line empty.
- Child teams should have a slash in the name, e.g.,
test1-team/test1-1-team
- Build out the parent structure in the input file before creating the child teams; e.g. have the
test1-team
come beforetest1-team/test1-1-team
in the file
- Child teams should have a slash in the name, e.g.,
- From there, run the script by passing in the
teams.csv
file and org name:
1
./create-teams-from-list.sh teams.csv my-org
Note: A parent team should exist before creating a child team, or at least should come first in the input file
Delete Teams
- Prepare a list of teams that you want to create and place in a CSV file, one per line, with the last line empty.
- Child teams should have a slash in the name, e.g.,
test1-team/test1-1-team
!!! Important !!!
Note that if a team has child teams, all of the child teams will be deleted as well
- Child teams should have a slash in the name, e.g.,
- From there, run the script by passing in the
teams.csv
file and org name:
1
./delete-teams-from-list.sh teams.csv my-org
Note: All child teams belonging to the parent team will be deleted as well
Summary
I originally built the create-teams-from-list.sh
script from a request from a blog reader, and then later built the delete teams script to simplify testing because if I was creating teams in an automated fashion, you know I had no interest in deleting the test teams manually 😀.
Please feel free to PR or share any improvements to these scripts! The terminal logging certainly isn’t the cleanest, but the scripts work and provide a decent amount of information that is relevant to the request.
Enjoy! 🚀