-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #88 from joshjohanning/add-all-organization-member…
…s-to-a-team.sh feat: add script to add all organization members to a team
- Loading branch information
Showing
2 changed files
with
34 additions
and
0 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
#!/bin/bash | ||
|
||
# gh cli's token needs to be able to admin org - run this first if it can't | ||
# gh auth refresh -h github.com -s admin:org | ||
|
||
# this script is currently cumulative-only; it won't remove any users from the team | ||
# (but this shouldn't matter, if someone gets pulled from org they won't be in team anymore anyway) | ||
|
||
if [ -z "$1" ]; then | ||
echo "Usage: $0 <org> <team>" | ||
echo "Example: ./add-all-organization-members-to-a-team.sh joshjohanning-org all-users" | ||
exit 1 | ||
fi | ||
|
||
org="$1" | ||
team="$2" | ||
|
||
# Define color codes | ||
RED='\033[0;31m' | ||
NC='\033[0m' # No Color | ||
|
||
members=$(gh api /orgs/$org/members --jq '.[].login' --paginate) | ||
|
||
# loop thru each member and gracefully try to add them to a team | ||
for member in $members; do | ||
echo "Adding $member to $team" | ||
if ! gh api -X PUT /orgs/$org/teams/$team/memberships/$member -f "role=member"; then | ||
echo -e "${RED}Failed to add $member to $team${NC}" | ||
fi | ||
done |