forked from githubtraining/training-manual
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclean-up-class
More file actions
executable file
·48 lines (39 loc) · 1.37 KB
/
clean-up-class
File metadata and controls
executable file
·48 lines (39 loc) · 1.37 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
#!/usr/bin/env bash
#
# Cleanup Class
# shellcheck disable=SC1091
source "$HOME/.trainingmanualrc"
#################################################################
# NOTE: You must have a personal access token (PAT) #
# saved to your environment variables to use this script. #
# We recommend a dedicated service account (e.g. githubteacher) #
#################################################################
# GLOBALS
COLLAB_REPO=$1
function GetNames() {
# Get the collabs
IFS=" " read -ra COLLABS <<<"$(
curl -s -S -u "$TOKEN_OWNER:$TEACHER_PAT" -X GET "https://$INSTANCE_URL/repos/$CLASS_ORG/$COLLAB_REPO/collaborators?affiliation=direct&per_page=100" | jq -r 'map(.login) | unique | @sh' | tr -d \'
)" >>log.out 2>&1
# Clean up conflict repos based on collaborators in the inital class repo
for USER_NAME in "${COLLABS[@]}"; do
# Clean up conflict and games repos for the user
CleanUpRepo "conflict-practice-$USER_NAME"
CleanUpRepo "github-games-$USER_NAME"
done
}
function CleanUpRepo() {
# Get the Repo
REPO=$1
# Get repo status
REPO_STATUS=$(curl -s -S -i -u "$TOKEN_OWNER:$TEACHER_PAT" -X GET "https://$INSTANCE_URL/repos/$CLASS_ORG/$REPO" | grep "^Status:") >>log.out 2>&1
# Check the return
if
echo "$REPO_STATUS" | grep -iq "200"
then
# Remove the repo
./remove-repo "$REPO"
fi
}
# Get User names
GetNames