-
Notifications
You must be signed in to change notification settings - Fork 0
/
create_github_teams.sh
54 lines (46 loc) · 1.2 KB
/
create_github_teams.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#! /bin/bash
ORGANIZATION=$1
TEAM_NAME=$2
TEAM_DESCRIPTION=$3
TEAM_PERMISSION=$4
TEAM_NOTIFICATION_SETTING=$5
TEAM_PRIVACY=$6
TEAM_OWNERS=$7
# Check if the variable is empty or not provided
if [ -z "$ORGANIZATION" ]; then
echo "Error: Organization not provided."
exit 1
fi
if [ -z "$TEAM_NAME" ]; then
echo "Error: Team name is not provided"
exit 1
fi
# Convert TEAM_OWNERS to an array
IFS=',' read -ra TEAM_OWNERS_ARRAY <<< "$TEAM_OWNERS"
# Construct maintainers array
MAINTAINERS_ARRAY="["
for owner in "${TEAM_OWNERS_ARRAY[@]}"; do
MAINTAINERS_ARRAY+="\"$owner\","
done
MAINTAINERS_ARRAY="${MAINTAINERS_ARRAY%,}" # Remove trailing comma
MAINTAINERS_ARRAY+="]"
# Construct JSON data
JSON_DATA=$(cat <<EOF
{
"name": "$TEAM_NAME",
"description": "$TEAM_DESCRIPTION",
"maintainers": $MAINTAINERS_ARRAY,
"permission": "$TEAM_PERMISSION",
"notification_setting": "$TEAM_NOTIFICATION_SETTING",
"privacy": "$TEAM_PRIVACY"
}
EOF
)
curl -L \
-X POST \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer $GH_TOKEN" \
-H "X-GitHub-Api-Version: 2022-11-28" \
https://api.github.com/orgs/$ORGANIZATION/teams \
-d "$JSON_DATA"
echo "Created github team: $TEAM_NAME"