-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgitlab_fetch_group_projects
executable file
·81 lines (68 loc) · 1.77 KB
/
gitlab_fetch_group_projects
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#!/usr/bin/env bash
set -euo pipefail
SOFT=$(basename "$0")
err() {
>&2 echo "$SOFT: $*"
}
usage() {
echo "$SOFT: usage"
echo
echo " $SOFT <group>"
echo
echo " group: the gitlab group to clone"
echo
echo " ENVIRONMENT"
echo
echo " GITLAB_TOKEN with permission granted to [I don't remember right now, feel free to help]"
echo " it can be generated at https://gitlab.com/-/profile/personal_access_tokens"
echo
echo " GITLAB_HOST by default is gitlab.com"
echo
echo " EXAMPLES"
echo
echo ' export GITLAB_TOKEN=glpat-AZEazeazeAZEaze'
echo ' export GITLAB_HOST=gitlab.com'
echo ' gitlab_fetch_group_projects pag-station | while read -r ssh path; do echo git clone "$ssh" "$WORKSPACE/$path"; done'
echo
echo ' will clone everything accessible under the group gitlab.com/pag-station '
echo
}
args=()
while (( $# )); do
cmd=$1
shift
case "$cmd" in
-h|--help|help)
usage
exit 0
;;
*)
args+=("$cmd")
;;
esac
done
if ! command -v curl > /dev/null; then
err "curl is missing"
exit 1;
fi
if ! command -v jq > /dev/null; then
err "jq is missing"
exit 1;
fi
set -- "${args[@]}"
GITLAB_HOST=${GITLAB_HOST:-gitlab.com}
GITLAB_GROUP=$1
GITLAB_TOKEN=${GITLAB_TOKEN:-}
parseContent () {
jq -r ".[] | [ .ssh_url_to_repo, .path_with_namespace ] | @tsv"
}
page=1
while true; do
url="https://${GITLAB_HOST}/api/v4/groups/$GITLAB_GROUP/projects?include_subgroups=true&page=$page&archived=false"
req=$(curl -s --header "PRIVATE-TOKEN: $GITLAB_TOKEN" "$url")
if [ "$req" == "[]" ]; then
exit 0;
fi
((page+=1))
parseContent <<<"$req"
done