-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgitlab-clone-group.sh
executable file
·60 lines (46 loc) · 1.56 KB
/
gitlab-clone-group.sh
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
#! /bin/zsh
#echo "TODO: this script is WIP"
#exit 1
usage() {
echo "Usage: $0 <GROUP_NAME>"
}
# set -x
if [ -z "$1" ]; then # if $1 is empty
usage
exit 1
fi
# Remove if using group ID instead of path
# if [ ! -d "$1" ]; then # if $1 directory does not exist
# echo "Creating directory: $1"
# mkdir -p "$1"
# fi
# glab api groups/$1/projects | jq -r '.[].web_url' | xargs -n1 -I {} echo "git clone {} $1"
# glab api groups/$1/projects | jq -r '.[].web_url' | xargs -n1 -I {} git clone --recurse-submodules {} $1
# jq explanation:
# -c # compact output
# .[] # for each item in array
echo "Fetching projects for group: $1"
PROJECTS=$(glab api groups/$1/projects | jq -c ".[]")
echo "PROJECTS=$PROJECTS"
# echo $PROJECTS | jq -r '.[].web_url' | xargs -n1 -I {} echo "git clone --recurse-submodules {} $1"
echo $PROJECTS | while IFS= read -r PROJECT; do
# get the project.name from jq
PROJECT_NAME=$(echo $PROJECT | jq -r '.name')
echo "PROJECT_NAME: $PROJECT_NAME"
URL=$(echo $PROJECT | jq -r '.web_url')
DIRECTORY=$1/$PROJECT_NAME
echo " git clone $URL $DIRECTORY"
git clone --recurse-submodules $URL $DIRECTORY
done
echo "Done cloning projects for group: $1"
SUBGROUPS=$(glab api groups/$1/subgroups | jq -c ".[]")
echo $SUBGROUPS | while IFS= read -r GROUP; do
echo "TODO looks like this loop breaks when newline are in the string"
echo "GROUP: $GROUP"
# GROUP_NAME=$(echo $GROUP | jq -r '.name')
# echo "GROUP_NAME: $GROUP_NAME"
echo "clone subgroups"
gitlab-clone-group.sh $GROUP
done
echo "Done cloning subgroups for group: $1
exit 0