-
Notifications
You must be signed in to change notification settings - Fork 0
/
set-team
executable file
·63 lines (49 loc) · 2.18 KB
/
set-team
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
55
56
57
58
59
60
61
62
63
#!/bin/bash
USAGE="Sets or changes github team id which is needed for all operations.\n"
USAGE+="Usage: albert $(basename "$0") \"github team name\"\n"
USAGE+="Example: albert $(basename "$0") \"ConMon\""
([[ "$1" == "help" ]] || [[ "$2" == "help" ]] ) && { echo -e "$USAGE"; exit 0; }
MY_DIR="$(dirname "$0")"
source "$MY_DIR/util"
check_access_token
GIVEN_NAME="${2:-$1}"
for i in 1 2 3 4 5 6 7 8 9; do
TEAM_FILTER="map(select(.name | contains(\"$GIVEN_NAME\"))) | map(.name, .id) | .[0]"
TEAM_ID_FILTER="map(select(.name | contains(\"$GIVEN_NAME\"))) | map(.name, .id) | .[1]"
TEAM_NAME=$(http GET "https://api.github.com/orgs/AutoScout24/teams?page=$i&per_page=30&access_token=$ACCESS_TOKEN" | jq "$TEAM_FILTER")
TEAM_ID=$(http GET "https://api.github.com/orgs/AutoScout24/teams?page=$i&per_page=30&access_token=$ACCESS_TOKEN" | jq "$TEAM_ID_FILTER")
if [[ "$TEAM_NAME" == "" ]] || [[ "$TEAM_NAME" == null ]]; then
echo "Searching, please wait!"
continue
else
echo -e "Found team name and id: $TEAM_NAME\n"
read -p "Is this correct team? [y/N] " -n 1 -r; echo
if [[ $REPLY =~ ^[Yy]$ ]]; then
echo $TEAM_ID > "$MY_DIR/team-id.albert.txt"
echo "Team added successfully"
exit 0
else
continue
fi
fi
done
echo -e "I couldn't find the team :( \nLet's try another way\n"
read -p "Please enter team slug (check github team url, for example: github.com/orgs/AutoScout24/teams/team-slug):"
if [[ "$REPLY" == "" ]]; then
echo "Empty slug is not accepted. Please use correct team name or slug."
exit 1
fi
for i in 1 2 3 4 5; do
TEAM_ID_FILTER="map(select(.slug | contains(\"$REPLY\"))) | map(.name, .id) | .[1]"
TEAM_ID=$(http GET "https://api.github.com/orgs/AutoScout24/teams?page=$i&per_page=100&access_token=$ACCESS_TOKEN" | jq "$TEAM_ID_FILTER")
if [[ "$TEAM_ID" == "" ]] || [[ "$TEAM_ID" == null ]]; then
echo "Searching, please wait!"
continue
else
echo $TEAM_ID > "$MY_DIR/team-id.albert.txt"
echo "Team added successfully"
exit 0
fi
done
echo "Given slug wasn't found! Please use correct team name or slug."
exit 1