Skip to content

Commit ff1be4c

Browse files
Invite users to org (#93)
* Invite users to org * style: fix linting --------- Co-authored-by: Josh Johanning <joshjohanning@github.com>
1 parent e67f4e2 commit ff1be4c

File tree

2 files changed

+44
-0
lines changed

2 files changed

+44
-0
lines changed

gh-cli/README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1142,6 +1142,10 @@ Example output:
11421142
],
11431143
```
11441144

1145+
### invite-users-to-organization-from-list.sh
1146+
1147+
Adds users to an organization team from a CSV input list.
1148+
11451149
### lock-repository-with-migration.sh
11461150

11471151
Creates a (mostly) empty migration for a given organization repository so that it can create a lock.
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#!/bin/bash
2+
3+
# Adds users to an organization team from a CSV input list
4+
5+
# Usage:
6+
# 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
7+
# - DO NOT REMOVE TRAILING NEW LINE IN THE INPUT CSV FILE
8+
# Step 2: ./invite-users-to-organization-from-list.sh users.csv <org> <team>
9+
10+
if [ $# -lt "2" ]; then
11+
echo "Usage: $0 <users-file-name> <org>"
12+
exit 1
13+
fi
14+
15+
if [ ! -f "$1" ]; then
16+
echo "File $1 does not exist"
17+
exit 1
18+
fi
19+
20+
filename="$1"
21+
org="$2"
22+
23+
while read -r repofull ;
24+
do
25+
IFS='/' read -ra data <<< "$repofull"
26+
27+
user=${data[0]}
28+
29+
echo "Adding user to org: $user"
30+
31+
response=$(gh api \
32+
--method POST \
33+
-H "Accept: application/vnd.github+json" \
34+
-H "X-GitHub-Api-Version: 2022-11-28" \
35+
/orgs/$org/invitations \
36+
-f "email=${user}" -f "role=direct_member")
37+
38+
echo $response
39+
40+
done < "$filename"

0 commit comments

Comments
 (0)