-
Notifications
You must be signed in to change notification settings - Fork 282
/
clean-up-class
executable file
·44 lines (35 loc) · 1.29 KB
/
clean-up-class
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
#!/usr/bin/env bash
#
# Deletes practice repos associated with a given day 1 repo
# shellcheck disable=SC1091
source "$HOME/.trainingmanualrc"
# shellcheck source=script/shared_functions
source ./shared_functions
#################################################################
# 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) #
#################################################################
# shell variables
collab_repo=$1
org_url="https://$TOKEN_OWNER:$TEACHER_PAT@$ROOT_URL/$CLASS_ORG"
org_repos_endpoint="https://$INSTANCE_URL/repos/$CLASS_ORG"
delete_repos() {
for username in "${collaborators[@]:?}"; do
# Clean up conflict and games repos for the user
delete_repo "conflict-practice" "$username"
delete_repo "github-games" "$username"
done
}
delete_repo() {
practice_repo_name=$1
student=$2
if repo_is_reachable "$org_url/$practice_repo_name-$student"; then
echo "Deleting $practice_repo_name-$student... "
# delete the existing practice repo
http --auth "$TOKEN_OWNER:$TEACHER_PAT" \
DELETE "$org_repos_endpoint/$practice_repo_name-$student" >>log.out 2>&1
fi
}
get_collaborators "$collab_repo"
delete_repos