From f48c2ad71e2b9a926def16e91a6e0569801ceecb Mon Sep 17 00:00:00 2001 From: Bert Heyman Date: Sat, 30 Nov 2024 10:14:32 +0100 Subject: [PATCH 1/2] Invite users to org --- gh-cli/invite-users-to-org-from-list.sh | 40 +++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 gh-cli/invite-users-to-org-from-list.sh diff --git a/gh-cli/invite-users-to-org-from-list.sh b/gh-cli/invite-users-to-org-from-list.sh new file mode 100644 index 0000000..36116b5 --- /dev/null +++ b/gh-cli/invite-users-to-org-from-list.sh @@ -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-org-from-list.sh users.csv + +if [ $# -lt "2" ]; then + echo "Usage: $0 " + 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" From 8614351261ba8057e6f08afdea996acd55e72b80 Mon Sep 17 00:00:00 2001 From: Josh Johanning Date: Wed, 18 Dec 2024 20:27:36 -0600 Subject: [PATCH 2/2] style: fix linting --- gh-cli/README.md | 4 ++++ ...from-list.sh => invite-users-to-organization-from-list.sh} | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) rename gh-cli/{invite-users-to-org-from-list.sh => invite-users-to-organization-from-list.sh} (91%) mode change 100644 => 100755 diff --git a/gh-cli/README.md b/gh-cli/README.md index 093232b..c92e852 100644 --- a/gh-cli/README.md +++ b/gh-cli/README.md @@ -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. diff --git a/gh-cli/invite-users-to-org-from-list.sh b/gh-cli/invite-users-to-organization-from-list.sh old mode 100644 new mode 100755 similarity index 91% rename from gh-cli/invite-users-to-org-from-list.sh rename to gh-cli/invite-users-to-organization-from-list.sh index 36116b5..65a9219 --- a/gh-cli/invite-users-to-org-from-list.sh +++ b/gh-cli/invite-users-to-organization-from-list.sh @@ -5,7 +5,7 @@ # 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-org-from-list.sh users.csv +# Step 2: ./invite-users-to-organization-from-list.sh users.csv if [ $# -lt "2" ]; then echo "Usage: $0 "