Skip to content

Commit 4c7909c

Browse files
author
Andreas Schleifer
authored
add script to generate config based on a gitlab group (#336)
1 parent 346c970 commit 4c7909c

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

scripts/generate_gitlab.sh

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#!/usr/bin/env bash
2+
3+
if [ -z "${GITLAB_TOKEN}" ]; then
4+
echo 'Please provide the environment variable $GITLAB_TOKEN'
5+
exit 1
6+
fi
7+
8+
if [ $# -lt 2 ]; then
9+
echo "Usage: $0 <gitlab_host> <gitlab_namespace> [</path/to/target.config>]"
10+
exit 1
11+
fi
12+
13+
prefix="$(pwd)"
14+
gitlab_host="${1}"
15+
namespace="${2}"
16+
config_file="${3:-./vcspull.yaml}"
17+
18+
current_namespace_path=""
19+
20+
curl --silent --show-error --header "Authorization: Bearer ${GITLAB_TOKEN}" "https://${gitlab_host}/api/v4/groups/${namespace}/projects?include_subgroups=true&per_page=100" \
21+
| jq -r '.[]|.namespace.full_path + " " + .path' \
22+
| LC_ALL=C sort \
23+
| while read namespace_path reponame; do
24+
if [ "${current_namespace_path}" != "${namespace_path}" ]; then
25+
current_namespace_path="${namespace_path}"
26+
27+
echo "${prefix}/${current_namespace_path}:"
28+
fi
29+
30+
# simplified config not working - https://github.com/vcs-python/vcspull/issues/332
31+
#echo " ${reponame}: 'git+ssh://git@${gitlab_host}/${current_namespace_path}/${reponame}.git'"
32+
33+
echo " ${reponame}:"
34+
echo " url: 'git+ssh://git@${gitlab_host}/${current_namespace_path}/${reponame}.git'"
35+
echo " remotes:"
36+
echo " origin: 'ssh://git@${gitlab_host}/${current_namespace_path}/${reponame}.git'"
37+
done \
38+
| tee "${config_file}"

0 commit comments

Comments
 (0)