File tree Expand file tree Collapse file tree 2 files changed +34
-0
lines changed
Expand file tree Collapse file tree 2 files changed +34
-0
lines changed Original file line number Diff line number Diff line change @@ -65,6 +65,10 @@ See the [docs](https://cli.github.com/manual/gh_auth_login) for further informat
6565
6666## Scripts
6767
68+ ### add-all-organization-members-to-a-team.sh
69+
70+ Adds all members of an organization to a team.
71+
6872### add-branch-protection-status-checks.sh
6973
7074Adds a status check to the branch protection status check contexts.
Original file line number Diff line number Diff line change 1+ #! /bin/bash
2+
3+ # gh cli's token needs to be able to admin org - run this first if it can't
4+ # gh auth refresh -h github.com -s admin:org
5+
6+ # this script is currently cumulative-only; it won't remove any users from the team
7+ # (but this shouldn't matter, if someone gets pulled from org they won't be in team anymore anyway)
8+
9+ if [ -z " $1 " ]; then
10+ echo " Usage: $0 <org> <team>"
11+ echo " Example: ./add-all-organization-members-to-a-team.sh joshjohanning-org all-users"
12+ exit 1
13+ fi
14+
15+ org=" $1 "
16+ team=" $2 "
17+
18+ # Define color codes
19+ RED=' \033[0;31m'
20+ NC=' \033[0m' # No Color
21+
22+ members=$( gh api /orgs/$org /members --jq ' .[].login' --paginate)
23+
24+ # loop thru each member and gracefully try to add them to a team
25+ for member in $members ; do
26+ echo " Adding $member to $team "
27+ if ! gh api -X PUT /orgs/$org /teams/$team /memberships/$member -f " role=member" ; then
28+ echo -e " ${RED} Failed to add $member to $team ${NC} "
29+ fi
30+ done
You can’t perform that action at this time.
0 commit comments