Skip to content

Commit

Permalink
Invite users to org (#93)
Browse files Browse the repository at this point in the history
* Invite users to org

* style: fix linting

---------

Co-authored-by: Josh Johanning <joshjohanning@github.com>
  • Loading branch information
bertheyman and joshjohanning authored Dec 19, 2024
1 parent e67f4e2 commit ff1be4c
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
4 changes: 4 additions & 0 deletions gh-cli/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1142,6 +1142,10 @@ Example output:
],
```

### invite-users-to-organization-from-list.sh

Adds users to an organization team from a CSV input list.

### lock-repository-with-migration.sh

Creates a (mostly) empty migration for a given organization repository so that it can create a lock.
Expand Down
40 changes: 40 additions & 0 deletions gh-cli/invite-users-to-organization-from-list.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#!/bin/bash

# Adds users to an organization team from a CSV input list

# Usage:
# Step 1: Create a list of user emails in a csv file, 1 per line, with a trailing empty line at the end of the file
# - DO NOT REMOVE TRAILING NEW LINE IN THE INPUT CSV FILE
# Step 2: ./invite-users-to-organization-from-list.sh users.csv <org> <team>

if [ $# -lt "2" ]; then
echo "Usage: $0 <users-file-name> <org>"
exit 1
fi

if [ ! -f "$1" ]; then
echo "File $1 does not exist"
exit 1
fi

filename="$1"
org="$2"

while read -r repofull ;
do
IFS='/' read -ra data <<< "$repofull"

user=${data[0]}

echo "Adding user to org: $user"

response=$(gh api \
--method POST \
-H "Accept: application/vnd.github+json" \
-H "X-GitHub-Api-Version: 2022-11-28" \
/orgs/$org/invitations \
-f "email=${user}" -f "role=direct_member")

echo $response

done < "$filename"

0 comments on commit ff1be4c

Please sign in to comment.