-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcreate_repo.sh
More file actions
executable file
·58 lines (50 loc) · 1.82 KB
/
create_repo.sh
File metadata and controls
executable file
·58 lines (50 loc) · 1.82 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
53
54
55
56
57
58
#!/bin/bash
# Prerequistes: gh, git
# Modifiable variables - set per your usage
collaborators=('thisisamna' 'hadeer-r' 'HabibaYossre' 'Momen-MKadry')
repo_name="Linux-25-Training"
task_handler_app="https://github.com/apps/task-handler"
# Fetching the student's username
username=$(gh api user --jq '.login')
add_collaborators() {
for c in "${collaborators[@]}"
do
gh api -X PUT "/repos/$username/$repo_name/collaborators/$c" -f permission=write &> /dev/null
done
}
# Check if dir with the same name already exists
if [ -d $repo_name ]; then
echo "A directory with the name $repo_name already exists! Exiting..."
exit 1
fi
# Check if remote repo already exists
gh api repos/"$username/$repo_name" &> /dev/null
if [ $? = 0 ]; then
echo "Repo already exists on GitHub. Cloning..."
# Re-adding collaborators just in case
add_collaborators
gh repo clone "$username/$repo_name" &> /dev/null || exit 1
echo "Existing task repo cloned successfully!"
else
# Creating a new repo
echo "Creating new task repo..."
{
git init -b main $repo_name
cd $repo_name
git commit --allow-empty -m "repository setup"
gh repo create $repo_name --private --source=. --remote=origin
git push -u origin main
add_collaborators
} &> /dev/null
echo "Task repo created successfully!"
fi
echo "==============================="
echo "You will be redirected to GitHub to install the automation app."
echo "1. Click 'Configure'"
echo "2. Choose your GitHub account and click 'Install'"
echo "3. Change repository access to 'Only select repositories' and choose $repo_name"
echo "4. Click 'Save'"
echo "Press Enter to open the link in your browser: https://github.com/apps/task-handler"
read key
xdg-open "$task_handler_app" > /dev/null
echo "Repo initialization completed!"