Last active
June 21, 2023 11:49
-
-
Save dex4er/0acaa88a27e33e20b30bbde4d96349f6 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
## gitlab_clone_all.sh | |
## | |
## Copyright (c) 2023 Piotr Roszatycki <[email protected]>, MIT | |
## | |
## Requires curl and jq | |
GROUP_NAME="$1" | |
shift | |
if [[ -z $GROUP_NAME ]]; then | |
echo "Usage: $0 group-name" | |
exit 1 | |
fi | |
GITLAB_API="https://${GITLAB_HOST:-gitlab.com}/api/v4" | |
function api () { | |
local method="$1"; shift | |
local path="$1"; shift | |
curl -sf -X $method --header "PRIVATE-TOKEN: $GITLAB_TOKEN" "$GITLAB_API/$path" "$@" | |
} | |
function list_repos_in_group () { | |
local group_name="$1" | |
local page=1 | |
while : ; do | |
projects=$(api GET "groups/${group_name//\//%2F}/projects?page=$page" | jq -r '.[].path_with_namespace') | |
test -n "$projects" || break | |
echo "$projects" | |
((page++)) | |
done | |
} | |
function list_subgroups_in_group () { | |
local group_name="$1" | |
local page=1 | |
while : ; do | |
subgroups=$(api GET "groups/${group_name//\//%2F}/subgroups?page=$page" | jq -r '.[].full_path') | |
test -z "$subgroups" && break | |
echo "$subgroups" | |
((page++)) | |
done | |
} | |
function list_repos_in_all_subgroups () { | |
local group_name="$1" | |
list_repos_in_group "$group_name" | |
local group | |
for group in $(list_subgroups_in_group "$group_name"); do | |
list_repos_in_all_subgroups "$group" | |
done | |
} | |
list_repos_in_all_subgroups "$GROUP_NAME" | | |
while read -r repo; do | |
dir=${repo#$GROUP_NAME/} | |
if [[ -d $dir ]]; then | |
echo "$repo is already cloned" | |
continue | |
fi | |
git clone "https://git.swf.daimler.com/$repo.git" "$dir" "$@" | |
done |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
## gitlab_clone_all.sh | |
## | |
## Copyright (c) 2023 Piotr Roszatycki <[email protected]>, MIT | |
## | |
## Requires curl and jq | |
GROUP_NAME="$1" | |
shift | |
if [[ -z $GROUP_NAME ]]; then | |
echo "Usage: $0 group-name" | |
exit 1 | |
fi | |
GITLAB_API="https://${GITLAB_HOST:-gitlab.com}/api/v4" | |
function api () { | |
local method="$1"; shift | |
local path="$1"; shift | |
curl -sf -X $method --header "PRIVATE-TOKEN: $GITLAB_TOKEN" "$GITLAB_API/$path" "$@" | |
} | |
function list_repos_in_group () { | |
local group_name="$1" | |
local page=1 | |
while : ; do | |
projects=$(api GET "groups/${group_name//\//%2F}/projects?page=$page" | jq -r '.[].path_with_namespace') | |
test -n "$projects" || break | |
echo "$projects" | |
((page++)) | |
done | |
} | |
function list_subgroups_in_group () { | |
local group_name="$1" | |
local page=1 | |
while : ; do | |
subgroups=$(api GET "groups/${group_name//\//%2F}/subgroups?page=$page" | jq -r '.[].full_path') | |
test -z "$subgroups" && break | |
echo "$subgroups" | |
((page++)) | |
done | |
} | |
function list_repos_in_all_subgroups () { | |
local group_name="$1" | |
list_repos_in_group "$group_name" | |
local group | |
for group in $(list_subgroups_in_group "$group_name"); do | |
list_repos_in_all_subgroups "$group" | |
done | |
} | |
list_repos_in_all_subgroups "$GROUP_NAME" |
True. You can clone them all with glab
but you can't list them.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
glab repo pull -g $GROUPNAME -p --paginate
;)