forked from Skill17-WebTechnologies/competition-scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreate_team.sh
More file actions
executable file
·51 lines (44 loc) · 1.47 KB
/
create_team.sh
File metadata and controls
executable file
·51 lines (44 loc) · 1.47 KB
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
#!/bin/bash
# Check if the correct number of arguments are provided
if [ "$#" -ne 5 ]; then
echo "Usage: $0 <GITEA_TOKEN> <GITEA_URL> <ORG_NAME> <TEAM_NAME> <CAN_CREATE_ORG_REPO>"
exit 1
fi
# Set variables from script arguments
GITEA_TOKEN="$1"
GITEA_URL="$2"
ORG_NAME="$3"
TEAM_NAME="$4"
CAN_CREATE_ORG_REPO="$5"
# API endpoint to create a team in an organization
API_ENDPOINT="$GITEA_URL/api/v1/orgs/$ORG_NAME/teams"
# Create a new team in the specified organization
response=$(curl -k -s -X POST -H "Content-Type: application/json" \
-H "Authorization: token $GITEA_TOKEN" \
-d '{
"name": "'"$TEAM_NAME"'",
"can_create_org_repo": '"$CAN_CREATE_ORG_REPO"',
"units_map": {
"repo.actions": "read",
"repo.packages": "none",
"repo.code": "write",
"repo.issues": "write",
"repo.ext_issues": "none",
"repo.wiki": "admin",
"repo.pulls": "owner",
"repo.releases": "none",
"repo.projects": "none",
"repo.ext_wiki": "none"
}
}' \
"$API_ENDPOINT")
# Extract the team ID from the response
# team_id=$(echo $response | jq -r '.id')
team_id=$(echo "$response" | awk -F'"id":' '{print $2}' | awk -F',' '{print $1}')
# Check if the team was successfully created
if [ "$team_id" == "null" ]; then
echo "Failed to create team. Response: $response"
exit 1
fi
# Output the created team ID
echo "Created team ID: $team_id"