-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgitlab-group-clone.sh
More file actions
30 lines (28 loc) · 912 Bytes
/
gitlab-group-clone.sh
File metadata and controls
30 lines (28 loc) · 912 Bytes
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
#!/bin/bash
# Edit the GITLAB_TOKEN, GITLAB_BASE and "group/project" inside GRAPHQL_QUERY
GITLAB_TOKEN='PRIVATE_TOKEN'
GITLAB_BASE_URL='https://example.gitlab.com'
GRAPHQL_QUERY='{
"query": "query {
group(fullPath: \"group/project\") {
projects {
nodes {
name
sshUrlToRepo
}
}
}
}"
}'
repo_list=$(curl \
--header "Authorization: Bearer ${GITLAB_TOKEN}" \
--header "Content-Type: application/json" \
--request POST \
--data @- \
"${GITLAB_BASE_URL}/api/graphql" <<< "$GRAPHQL_QUERY" | jq --raw-output '.data.group.projects.nodes[] | "\(.name),\(.sshUrlToRepo)"')
while IFS= read -r line; do
name="$(echo $line | cut --delimiter=',' --fields=1)"
url="$(echo $line | cut --delimiter=',' --fields=2)"
echo "Cloning $name"
git clone $url
done <<< "$repo_list"