-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdelete_repo.sh
More file actions
52 lines (38 loc) · 1.01 KB
/
Copy pathdelete_repo.sh
File metadata and controls
52 lines (38 loc) · 1.01 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
52
#!/bin/bash
# Check input
if [ $# -ne 1 ]; then
echo "Usage: $0 <repo_file>"
exit 1
fi
REPO_FILE=$1
if [ ! -f "$REPO_FILE" ]; then
echo "File not found: $REPO_FILE"
exit 1
fi
read -p "Enter GitHub Username: " USERNAME
read -s -p "Enter GitHub Token: " TOKEN
echo ""
echo "Repositories that will be deleted:"
cat "$REPO_FILE"
echo ""
read -p "Are you sure you want to DELETE these repositories? (yes/no): " CONFIRM
if [ "$CONFIRM" != "yes" ]; then
echo "Deletion cancelled."
exit 0
fi
while IFS= read -r REPO
do
[ -z "$REPO" ] && continue
echo "Deleting repository: $REPO"
RESPONSE=$(curl -s -o /dev/null -w "%{http_code}" \
-X DELETE \
-u "$USERNAME:$TOKEN" \
"https://api.github.com/repos/$USERNAME/$REPO")
if [ "$RESPONSE" -eq 204 ]; then
echo "SUCCESS: Deleted $REPO"
else
echo "FAILED: Could not delete $REPO (HTTP $RESPONSE)"
fi
echo "---------------------------"
done < "$REPO_FILE"
echo "Deletion process completed."